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.

372 lines
11 KiB

6 years ago
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<time.h>
int year,month,day;
int day_of_month[12]={31,28,31,30,31,30,31,31,30,31,30,31};//ÿ<>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
int current_year,current_month,current_day;//<2F><>ǰ<EFBFBD><C7B0>ʱ<EFBFBD><CAB1>
/*******************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>********************/
int judgement(int year)/*<2A><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>*/
{
if(year%400==0||year%4==0&&year%100!=0)//<2F><><EFBFBD><EFBFBD><EFBFBD>ܱ<EFBFBD>400<30><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߱<EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>100
return 1;
else return 0;
}
int show_week(int year,int month,int day)
{
/*
<EFBFBD><EFBFBD>ʽ:w=(y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1)%7
w<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>y<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĺ<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>c<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>m<EFBFBD><EFBFBD><EFBFBD>·ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD>°<EFBFBD>13<EFBFBD>㣬2<EFBFBD>°<EFBFBD>14<EFBFBD><EFBFBD><EFBFBD>d<EFBFBD>ǵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
int w ,k; //<2F><>¼<EFBFBD><C2BC><EFBFBD>ܼ<EFBFBD>
int year_last=year%100,c=year/100 , m = month;
if (month==1 )
{
year_last-=1 ;
m=13 ;
}
else if (month==2)
{
year_last-=1;
m=14;
}
w = (year_last + year_last/4 + c/4 - 2*c +26*(m+1)/10+day-1);
if (w<0)
{
k=(w%7+7)%7;
}
else k=w%7;
return k ;
}
int current_time()
{
time_t timep;
struct tm *p;
time(&timep);
p=gmtime(&timep);
current_year=1900+p->tm_year;
current_month=1+p->tm_mon;
current_day=p->tm_mday;
}
/*------------------<2D><><EFBFBD><EFBFBD>һ -----------------*/
int print_year(int year)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
int i,k,j,frist_week;
printf("Please input the year whose calender you want to know:");
scanf("%d",&year) ;
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~The Calender of Year %d~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",year);
printf("\n");
if(judgement(year))//<2F><><EFBFBD><EFBFBD>judgement<6E><74><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
{
day_of_month[1]=29;//<2F><><EFBFBD><EFBFBD>
}
else day_of_month[1]=28;
for(i=1;i<13;i++)
{
frist_week=show_week(year,i,1);
printf(" %d<><64> \n",i);
printf("SUN\tMOD\tTUE\tWED\tTHU\tFRI\tSAT\n");
for(j=1;j<=frist_week-1;j++)
{
printf("\t");
if (j%7==0) printf ("\n");
}
for (k=1;k<=day_of_month[i-1];k++)
{
printf("%d\t",k);
if (j%7==0) printf ("\n");
j++;
}
printf("\n");
printf("\n");
printf("\n");
}
}
/*-------------------<2D><><EFBFBD>ܶ<EFBFBD>------------------*/
int print_year_month()//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
int x,y,i,frist_week;
printf("Please input the month whose calender you want to know");
do
{
scanf("%d.%d",&year,&month);
if(month<1||month>12)
{
printf("the month is error\n");
printf("Please input the month whose calender you want to know\n");
}
}while(month<1||month>12);
printf("*********************%d<><64>%d<><64>**********************\n",year,month);
if(judgement(year))
{
day_of_month[1]=29;
}
else day_of_month[1]=28;
frist_week=show_week(year,month,1);
printf ("SUN\tMOD\tTUE\tWED\tTHU\tFRI\tSAT\n");
for(x=1;x<=frist_week;x++)
{
printf("\t");
if (x%7==0) printf ("\n");
}
for (y=1;y<=day_of_month[month-1];y++)
{
printf("%d\t",y);
if (x%7==0) printf ("\n");
x++;
}
printf("\n");
}
/*-----------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>------------------*/
int sumdays(int year,int month,int day)
{
int days=0,days1=0,days2=0,days3=0,temp_day=0;//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>֮<EFBFBD><D6AE>
int i,judgement1,sum_days;//<2F><>ǰʱ<C7B0><CAB1>,<2C><>ʱ<EFBFBD><CAB1>
judgement1=judgement(year);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(year<current_year)/*******************<2A><><EFBFBD><EFBFBD>֮ǰ********************/
{
for(i=year+1;i<current_year;i++)//<2F><><EFBFBD><EFBFBD>2000<30><30>ָ2001-2018
{
if(judgement(i))//<2F>ж<EFBFBD>2001-2018֮<38><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
days=days+366;//<2F><>2001-2018֮<38><D6AE>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
else days=days+365;//<2F><>2001-2018֮<38><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
for(i=month;i<=12;i++)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
days1=days1+day_of_month[i-1];//<2F><><EFBFBD>·ݵ<C2B7><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
days2=days1+-day;//<2F><><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>·ݵ<C2B7><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
days3=days2+days;
for(i=0;i<current_month-1;i++)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>˶<EFBFBD><CBB6>ٸ<EFBFBD><D9B8><EFBFBD>
{
if(judgement1)
{
day_of_month[1]=29;
}
temp_day=temp_day+day_of_month[i];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD>·ݵ<C2B7><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
temp_day=temp_day+current_day;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD>·ݵ<C2B7><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sum_days=temp_day+days3;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
if (year > current_year )/***********<2A><><EFBFBD><EFBFBD>֮<EFBFBD><D6AE>**************///ͬ<><CDAC>
{
for (i =current_year+1;i < current_year ;i++)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if (judgement(i))
{
days=days+366;
}
else days+=365;
}
for (i = current_month+1;i<=12;i++)//<2F><><EFBFBD>껹ʣ<EABBB9><CAA3><EFBFBD>ٸ<EFBFBD><D9B8><EFBFBD>
{
days=days+day_of_month[i-1];//<2F><><EFBFBD>껹ʣ<EABBB9><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>
}
days=days+day_of_month[month-1]-current_day;
for (i = 0;i <month-1;i++ )
{
if (judgement1)
{
day_of_month[1]=29;
}
temp_day=temp_day+day_of_month[i];
}
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD>
temp_day = temp_day+ day;
sum_days=temp_day+days;
}
if(year==current_year)/**********************<2A><><EFBFBD><EFBFBD>***********************/
{
if(month <current_month)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>ڵ<EFBFBD>ǰ<EFBFBD>·<EFBFBD>֮ǰ
{
for (i=month+1;i<current_month;i++)//<2F><><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD><CBB6>ٸ<EFBFBD><D9B8>·<EFBFBD>
{
if (judgement1)//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
{
day_of_month[1]=29;
}
days=days+day_of_month[i];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><D0A9><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
}
sum_days=days+current_day+day_of_month[month-1]-day;//<2F><><EFBFBD><EFBFBD>Щ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>(<28><><EFBFBD>¹<EFBFBD><C2B9>˼<EFBFBD><CBBC><EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>»<EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
if (month>current_month)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>ڵ<EFBFBD>ǰ<EFBFBD>·<EFBFBD>֮<EFBFBD><D6AE>
{
for (i=current_month+1;i<month;i++)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·ݼ<C2B7>ȥ<EFBFBD><C8A5>ǰ<EFBFBD>·<EFBFBD>
{
if (judgement1)
{
day_of_month[1]=29;
}
days = days + day_of_month[i];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
sum_days=days+day+day_of_month[month-1]-current_day;//<2F><><EFBFBD><EFBFBD><EFBFBD>·ݼ<C2B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·ݵ<C2B7><DDB5><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>)<29>ټ<EFBFBD>ȥ<EFBFBD><C8A5>ǰ<EFBFBD>·<EFBFBD><C2B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
if (month==current_month)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>ڵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
sum_days=fabs(day-current_day);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>ֵ
}
return sum_days ;
}
int print(int year,int month,int day)
{
int week;
printf("Please input the day whose calender you want to kown");
do
{
scanf("%d.%d.%d",&year,&month,&day);
if(judgement(year))
{
day_of_month[1]=29;
}
printf("\n");
if(day<=0||day>day_of_month[month-1]);
printf("%d<><64>%d<><64>%d<><64><EFBFBD>ǣ<EFBFBD>",year,month,day);
}
while(day<=0||day>day_of_month[month-1]);
week=show_week(year,month,day);
switch(month)
{
case 1:switch(day)
{
case 1:printf("Ԫ<><D4AA>");
break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 2:switch(day)
{
case 14:printf("<22><><EFBFBD>˽<EFBFBD>");
break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 3:switch(day)
{
case 8:printf("<22><>Ů<EFBFBD><C5AE>");break;
case 12:printf("ֲ<><D6B2><EFBFBD><EFBFBD>");break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 4:switch(day)
{
case 1:printf("<22><><EFBFBD>˽<EFBFBD>");break;
case 22:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 5:switch(day)
{
case 1:printf("<22>Ͷ<EFBFBD><CDB6><EFBFBD>");break;
case 4:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 6:switch(day)
{
case 1:printf("<22><>ͯ<EFBFBD><CDAF>");break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 7:switch(day)
{
case 1:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");break;
case 26:printf("<22><><EFBFBD>ѽ<EFBFBD>");break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 8:switch(day)
{
case 1:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 9:switch(day)
{
case 10:printf("<22><>ʦ<EFBFBD><CAA6>");break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 10:switch(day)
{
case 1:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");break;
case 31:printf("<22><>ʥҹ");break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 11:switch(day)
{
case 11:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
case 12:switch(day)
{
case 24:printf("ƽ<><C6BD>ҹ");break;
case 25:printf("ʥ<><CAA5><EFBFBD><EFBFBD>");break;
default:printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
break;
}
printf("\n");
printf("%d<><64>%d<><64>%d<><64><EFBFBD><EFBFBD>:",year,month,day);
switch(week)
{
case 0:printf("Sunday");break;
case 1:printf("Monday");break;
case 2:printf("Tuesday");break;
case 3:printf("Wednesday");break;
case 4:printf("Thursday");break;
case 5:printf("Friday");break;
case 6:printf("Saturday");break;
}
printf("\n");
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECBBB9>%d<><64>\n",sumdays(year,month,day));
printf("\n");
}
/********************************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**************************/
int main()
{
int select;
printf("========================================<3D><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>========================================\n");
printf("\n");
printf("-------------------------------------<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>-------------------------------------\n");
printf("\n");
printf("------------------------------------------<2D><><EFBFBD>ܣ<EFBFBD>----------------------------------------\n");
printf("\n");
printf("***********************************1:<3A><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*************************************\n");
printf("\n");
printf("***********************************2:<3A><><EFBFBD><EFBFBD>ij<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>*************************************\n");
printf("\n");
printf("***********************************3:<3A><><EFBFBD><EFBFBD>ij<EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>*************************************\n");
printf("\n");
printf("***********************************0:<3A>˳<EFBFBD>***********************************************\n");
printf("\n");
printf("========================================================================================\n");
printf("\n");
while(1)
{
printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>\n");
scanf("%d",&select);
switch (select)
{
case 1:
print_year(year);
break;
case 2:
print_year_month();
break;
case 3:
current_time();
print(year,month,day);
sumdays(year,month,day);
break;
case 0:
break;
}
}
}