#include <stdio.h>
#include <stdbool.h>
bool isLeap(int y){ return ((!(y%4)) && (y%100)) || (!(y%400)); }
int ZellersCongruence(int d, int m, int y){
if(m < 3){ m += 12; y --; }
int h = (d + (13*(m+1))/5 + (y%100) + (y%100)/4 + (y/100)/4 - 2*(y/100))%7;
return ((h + 5)%7) + 1;
}
void calendar(int h, int m, int y){
/* h: day of the week for first day in the month */
h %= 7;
char* w[13] = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
printf("%s %d\n", w[m], m);
printf("====================\n");
printf(" S M T W T F S\n");
int n = 1;
int d = m == 2 && isLeap(y) ? 29 : m == 2 ? 28 : ((m < 8) && (m % 2)) || ((m > 7) && !(m % 2))? 31 : 30;
for(size_t i = 0; i < h; i++, n++) printf("%2s ", "");
for(size_t i = 1; i <= d; i++, n++){
printf("%2ld ", i);
if(!(n % 7)) printf("\n");
}
printf("\n====================\n");
}
void calendar_of_the_year(int y){
for(int m = 1; m < 13; m++){
int h = ZellersCongruence(1, m, y);
calendar(h, m, y);
printf("\n");
}
}
int weeks(int day, int month, int year){
int days = day;
for(int m = 1; m < month; m++) days += (m == 2 && isLeap(year) ? 29 : m == 2 ? 28 : ((m < 8) && (m % 2)) || ((m > 7) && !(m % 2))? 31 : 30);
return days/7 + 1;
}
int main(){
while(1){
int date[3] = {0}, d, m, y, h, a, b;
char* w[8] = {"", "一", "二", "三", "四", "五", "六", "日"};
for(int i = 0; i < 3; i++){
scanf("%d", &date[i]);
if(getchar() == '\n') break;
}
if(!date[0]) break;
int code = !date[1] ? 0 : !date[2] ? 1 : date[0] > date[2] ? 2 : 3;
switch(code){
case 0:
y = date[0];
calendar_of_the_year(y);
break;
case 1:
y = date[0];
m = date[1];
h = ZellersCongruence(1, m, y);
calendar(h, m, y);
break;
case 2:
y = date[0];
m = date[1];
d = date[2];
h = ZellersCongruence(1, m, y);
calendar(h, m, y);
a = weeks(d, m, y);
b = ZellersCongruence(d, m, y);
printf("该日期属于本年的第 %d 周,星期%s\n", a, w[b]);
break;
case 3:
m = date[0];
d = date[1];
y = date[2];
h = ZellersCongruence(1, m, y);
calendar(h, m, y);
a = weeks(d, m, y);
b = ZellersCongruence(d, m, y);
printf("该日期属于本年的第 %d 周,星期%s\n", a, w[b]);
break;
}
}
return 0;
}