You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
7.3 KiB

6 years ago
#include<stdio.h>
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("<EFBFBD><EFBFBD>2019<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>10<EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64>\n",num);
printf("%d<><64>%d<><64>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d\n",year,month,day,w);
if(month==1)
{
switch(day)
{
case 1: printf("Ԫ<EFBFBD><EFBFBD>\n");break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
}
else if(month==2)
{
switch(day)
{
case 14: printf("<EFBFBD><EFBFBD><EFBFBD>˽<EFBFBD>\n");
break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
}
else if(month==3)
{
switch(day)
{
case 8: printf("<EFBFBD><EFBFBD>Ů<EFBFBD><EFBFBD>\n");
break;
case 12: printf("ֲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
}
else if(month==4)
{
switch(day)
{
case 1: printf("<EFBFBD><EFBFBD><EFBFBD>˽<EFBFBD>\n");
break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
}
else if(month==5)
{
switch(day)
{
case 1: printf("<EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>\n");
break;
case 4: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
}
else if(month==6)
{
switch(day)
{
case 1: printf("<EFBFBD><EFBFBD>ͯ<EFBFBD><EFBFBD>\n");
break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
}
else if(month==7)
{
switch(day)
{
case 1: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
}
else if(month==8)
{
switch(day)
{
case 1: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
}
else if(month==9)
{
switch(day)
{
case 10: printf("<EFBFBD><EFBFBD>ʦ<EFBFBD><EFBFBD>\n");
break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
}
else if(month==10)
{
switch(day)
{
case 1: printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
}
}
return 0;
}