#include int main(void) { int i=0,j,w,year,month,day,a,b,c=1,d=0,num=0; char n[10]; int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; printf ("Please input the year whose calendar you want to know:"); while ( (n[i]=getchar() )!='\n') { i++; if(n[i]==EOF) break; } printf("\nExample:20190110\n"); year=(n[0]-48)*1000+(n[1]-48)*100+(n[2]-48)*10+(n[3]-48); if (year%4==0&&year%100!=0||year%400==0) m[2]=29; w = (year+(year-1)/4-(year-1)/100+(year-1)/400)%7; if(i>0&&i<=4) { printf("===============The Calendar of Year %d ===============\n",year); for(j=1;j<=12;j++) { c=1; printf(" %d\n MON TUE WED THU FRI SAT SUM\n",j); for(a=1;a<=42;a++) { if(a>=w) { printf("%4d",c); c++; } else printf(" "); if(a%7==0) printf("\n"); if(c>m[j]) break; } d=d+m[j]; w= (year+(year-1)/4-(year-1)/100+(year-1)/400)%7+d%7; printf("\n"); } } else if(i>4&&i<=6) { month=(n[4]-48)*10+(n[5]-48); printf(" %d\n MON TUE WED THU FRI SAT SUM\n",month); if(month!=1) { for(j=1;j<=month;j++) d=d+m[j-1]; w=((year+(year-1)/4-(year-1)/100+(year-1)/400)+d)%7; } for(a=1;a<=42;a++) { if(a>=w) { printf("%4d",c); c++; } else printf(" "); if(a%7==0) printf("\n"); if(c>m[month]) break; } } else if(i>6&&i<=8) { month=(n[4]-48)*10+(n[5]-48); day=(n[6]-48)*10+(n[7]-48); if(year>2019) { num=(year-2019)*365+(year-2016)/4; for(j=1;j<=month;j++) d=d+m[j]; num=num+d+day+10; } else if(year<2019) { num=(2019-year)*365+(2020-year)/4; for(j=1;j<=month;j++) d=d+m[j]; num=num+d+day+10; } else if(year==2019) { for(j=1;j<=month;j++) d=d+m[j-1]; num=num+d+day-10; } w=((year+(year-1)/4-(year-1)/100+(year-1)/400)+d)%7; printf("距2019年1月10日有%d天\n",num); printf("%d年%d月%d日是星期%d\n",year,month,day,w); if(month==1) { switch(day) { case 1: printf("元旦\n");break; default:printf("今天不是阳历节日!\n"); } } else if(month==2) { switch(day) { case 14: printf("情人节\n"); break; default:printf("今天不是阳历节日!\n"); } } else if(month==3) { switch(day) { case 8: printf("妇女节\n"); break; case 12: printf("植树节\n"); break; default:printf("今天不是阳历节日!\n"); } } else if(month==4) { switch(day) { case 1: printf("愚人节\n"); break; default:printf("今天不是阳历节日!\n"); } } else if(month==5) { switch(day) { case 1: printf("劳动节\n"); break; case 4: printf("青年节\n"); break; default:printf("今天不是阳历节日!\n"); } } else if(month==6) { switch(day) { case 1: printf("儿童节\n"); break; default:printf("今天不是阳历节日!\n"); } } else if(month==7) { switch(day) { case 1: printf("建党节\n"); break; default:printf("今天不是阳历节日!\n"); } } else if(month==8) { switch(day) { case 1: printf("建军节\n"); break; default:printf("今天不是阳历节日!\n"); } } else if(month==9) { switch(day) { case 10: printf("教师节\n"); break; default:printf("今天不是阳历节日!\n"); } } else if(month==10) { switch(day) { case 1: printf("国庆节\n"); break; default:printf("今天不是阳历节日!\n"); } } } return 0; }