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.

360 lines
6.5 KiB

6 years ago
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int monthdays[12] = {31,28,31,30,31,30,31,31,30,31,30,31} ;
char yearr(int year)
{
if (year%4==0&&year%100||year%400==0)
return 1;
else
return 0;
}
int midmonthday(int m1 , int m2, int y)
{
int i ;
int s ;
s = 0 ;
for(i = m1 + 1 ; i < m2 ; i++)
{
s =s+ monthdays[i-1] ;
if(i == 2)
{
if(yearr(y))
{
s++ ;
}
}
}
return s ;
}
int SameYearDays(int y1 , int m1 , int d1 , int y2 , int m2 , int d2)
{
int Days ;
if(m1 == m2)
{
Days =abs(d2 - d1) ;
}
else
{
Days = abs(monthdays[m1 - 1] - d1) ;
if(m1 == 2)
{
if(yearr(y1))
{
Days++ ;
}
}
if((m1 + 1) != m2)
{
Days += midmonthday(m1 , m2, y1);
}
Days += d2 ;
}
return Days;
}
int GetMidYearDays(int y1,int y2)
{
int days=0;
int i=0;
for (i=y1+1;i<y2;i++)
{
if (yearr(i-1))
{
days+=366;
}
else
days+=365;
}
return days;
}
int distanceYearDays(int y1 , int m1 , int d1 , int y2 , int m2 , int d2)
{
int days;
if (y1==y2)
{
days=SameYearDays( y1 ,m1 ,d1 , y2 , m2 ,d2);
}
else
{
days=monthdays[m1+1]-d1;
if((y1+1) != y2)
{
days+=GetMidYearDays(y1,y2);
}
days+=midmonthday(m1-1,13,y1);
if(m2==1)
{
days+=d2;
}
else
{
days+=midmonthday(1,m2,y2);
days+=d2;
}
}
return days;
}
int printfweek()
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<EFBFBD><EFBFBD>һ","<EFBFBD>ܶ<EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
} int GetWeek(int year,int month)
{
int m[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int day=0,week,i;
switch (month)
{
case 1:
day = 1;
break;
case 2:
day = m[0] + 1;
break;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
{if (yearr(year) == true)
m[1] = 29;
for (i=0;i<month-1;i++)
{
day = day + m[i];
}
}
day = day + 1;
break;
}
week = ((year-1) + (year-1)/4 - (year-1)/100 + (year-1)/400 + day) % 7;
return week;
}
int tian(int month,int year)
{
int day;
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:day=31;break;
case 4:
case 6:
case 9:
case 11:day=30;break;
case 2:{
if(year%400==0||(year%4==0&&year%100!=0))
day=29;
else
day=28;
}
break;
}
return day;
}
int prifirst(int month,int year)
{
int b;
if (month<3)
{
month=month+12;
year--;
}
b=(1+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7;
return b;
}
int prtmonth(int month)
{
switch (month)
{
case 1:printf("%26s\n","һ<EFBFBD><EFBFBD>\n");break;
case 2:printf("%26s\n","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");break;
case 3:printf("%26s\n","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");break;
case 4:printf("%26s\n","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");break;
case 5:printf("%26s\n","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");break;
case 6:printf("%26s\n","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");break;
case 7:printf("%26s\n","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");break;
case 8:printf("%26s\n","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");break;
case 9:printf("%26s\n","<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");break;
case 10:printf("%26s\n","ʮ<EFBFBD><EFBFBD>\n");break;
case 11:printf("%26s\n","ʮһ<EFBFBD><EFBFBD>\n");break;
case 12:printf("%26s\n","ʮ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");break;
}
}
int hello()
{ int a;
int year,month,i,c,week;
printf("--------------------\n");
printf(" 1:<3A><>ѯijһ<C4B3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf(" 2:<3A><>ѯij<D1AF><C4B3>ij<EFBFBD><C4B3><EFBFBD>м<EFBFBD><D0BC><EFBFBD>\n");
printf(" 3:<3A><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf(" 4<><34>ѯij<D1AF><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD>\n") ;
printf(" 5<>ж<EFBFBD><D0B6>Ƿ<EFBFBD>Ϊ<EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>\n");
printf(" 6<><36><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>\n") ;
scanf("%d",&a);
switch(a)
{
case 1:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n:");
scanf("%d",&year);
for (month=1; month<=12; month++) {
c=1;
prtmonth(month);
printfweek();
week=prifirst(month,year);
if (week!=6)
for (i=0; i<=week; i++) {
printf("\t");
c++;
}
for (i=1; i<=tian(month,year); i++,c++)
{
printf("%d\t",i);
if (c%7==0)
{
printf("\n");
}
}
printf("\n");
}
return 0;
break;
case 2:int day;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>\n");
scanf("%d%d",&year,&month);
day=tian(month,year);
printf("%d<><64>%d<><64><EFBFBD><EFBFBD>%d<><64>",year,month,day);
return 0;
break;
case 3:int Year1 ,Month1 ,Day1 ,Year2 ,Month2 ,Day2;
int Days ;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><> <20><> <20><>)<29><>\n");
scanf("%d%d%d",&Year1,&Month1,&Day1);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><> <20><> <20><>)<29><>\n");
scanf("%d%d%d",&Year2,&Month2,&Day2);
Days = distanceYearDays(Year1, Month1,Day1,Year2,Month2,Day2);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>%d\n" , Days);
break;
case 4: int y,m,d,c,w;
printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>գ<EFBFBD>");
scanf ("%d %d %d", &y, &m, &d);
if (m==1||m==2)
{
y--;
m+=12;
}
c = y / 100;
y = y - c * 100;
w = (c/4)-2*c+(y+y/4)+(13*(m+1)/5)+d-1;
while(w<0)
w += 7;
w %= 7;
if (w==0)
printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
else printf ("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d\n", w);
return 0;
break;
printf("\n");
case 5:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%d%d%d",&year,&month,&day);
switch(month)
{
case 1:if(day==1)
printf("Ԫ<EFBFBD><EFBFBD>\n");
break;
case 4:if(day==5)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
case 5:if(day==1)
printf("<EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>\n");
break;
case 6:if(day==1)
printf("<EFBFBD><EFBFBD>ͯ<EFBFBD><EFBFBD>\n");
break;
case 7:if(day==1)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
case 8:if(day==1)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
case 9:if(day==10)
printf("<EFBFBD><EFBFBD>ʦ<EFBFBD><EFBFBD>\n");
break;
case 10:if(day==1)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
default:printf("error");
}printf("\n");
break;
case 6:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>");
scanf("%d%d",&y,&m);
printf(" %d<><64>%d<><64>\n",y,m);
printf(" һ <20><> <20><> <20><> <20><> <20><> <20><>\n");
week = GetWeek(y,m);
if(week == 0)
week = 7;
for (i = 1;i < week; i++)
{
printf(" ");
}
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
if (yearr(y) == 1)
month[1] = 29;
for(i=1;i<=month[m-1];i++)
{
printf("%3d",i);
if((i+week-1) % 7 == 0)
printf("\n");
}
printf("\n");
}
} int main()
{
int x;
while (1)
{
printf("-------------<2D><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>-----------\n");
printf(" 1:<3A><><EFBFBD>ز˵<D8B2> \n");
printf(" 2:<3A>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD> \n");
printf(" 3:ִ<>в<EFBFBD><D0B2><EFBFBD> \n");
printf("\t" );
printf("ѡ<EFBFBD><EFBFBD>Ҫִ<EFBFBD>еIJ<EFBFBD><EFBFBD><EFBFBD>: ");
scanf("%d",&x);
printf("\n");
if(x==2)
break;
switch(x)
{
case 1: break;
case 3: hello();break;
default:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
break;
}
}
return 0;
}