|
|
@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
#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 ds ;
|
|
|
|
|
|
|
|
ds = 0 ;
|
|
|
|
|
|
|
|
for(i = m1 + 1 ; i < m2 ; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ds =ds+ monthdays[i-1] ;
|
|
|
|
|
|
|
|
if(i == 2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if(yearr(y))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ds++ ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ds ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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","周日","周一","周二","周三","周四","周五","周六");
|
|
|
|
|
|
|
|
} 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","一月\n");break;
|
|
|
|
|
|
|
|
case 2:printf("%26s\n","二月\n");break;
|
|
|
|
|
|
|
|
case 3:printf("%26s\n","三月\n");break;
|
|
|
|
|
|
|
|
case 4:printf("%26s\n","四月\n");break;
|
|
|
|
|
|
|
|
case 5:printf("%26s\n","五月\n");break;
|
|
|
|
|
|
|
|
case 6:printf("%26s\n","六月\n");break;
|
|
|
|
|
|
|
|
case 7:printf("%26s\n","七月\n");break;
|
|
|
|
|
|
|
|
case 8:printf("%26s\n","八月\n");break;
|
|
|
|
|
|
|
|
case 9:printf("%26s\n","九月\n");break;
|
|
|
|
|
|
|
|
case 10:printf("%26s\n","十月\n");break;
|
|
|
|
|
|
|
|
case 11:printf("%26s\n","十一月\n");break;
|
|
|
|
|
|
|
|
case 12:printf("%26s\n","十二月\n");break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int hello()
|
|
|
|
|
|
|
|
{ int a;
|
|
|
|
|
|
|
|
int year,month,i,c,week;
|
|
|
|
|
|
|
|
printf("1:查询某一年日历\n2:查询某年某月有几天\n3:查询两天之间相差多少天\n4查询某天是星期几\n5判断是否为节假日\n6输出某年月日历\n");
|
|
|
|
|
|
|
|
printf("请输入选项:\n") ;
|
|
|
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
|
|
|
switch(a)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:printf("年份\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("输入年月:\n");
|
|
|
|
|
|
|
|
scanf("%d%d",&year,&month);
|
|
|
|
|
|
|
|
day=tian(month,year);
|
|
|
|
|
|
|
|
printf("%d年%d月有%d天",year,month,day);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:int Year1 ,Month1 ,Day1 ,Year2 ,Month2 ,Day2;
|
|
|
|
|
|
|
|
int Days ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("输入第一个日期(年 月 日):\n");
|
|
|
|
|
|
|
|
scanf("%d%d%d",&Year1,&Month1,&Day1);
|
|
|
|
|
|
|
|
printf("输入第二个日期(年 月 日):\n");
|
|
|
|
|
|
|
|
scanf("%d%d%d",&Year2,&Month2,&Day2);
|
|
|
|
|
|
|
|
Days = distanceYearDays(Year1, Month1,Day1,Year2,Month2,Day2);
|
|
|
|
|
|
|
|
printf("两个日期相差的天数为:%d\n" , Days);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: int y,m,d,c,w;
|
|
|
|
|
|
|
|
printf ("输入年 月 日:");
|
|
|
|
|
|
|
|
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 ("星期日");
|
|
|
|
|
|
|
|
else printf ("星期%d\n", w);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
printf("请输入日期:\n");
|
|
|
|
|
|
|
|
scanf("%d%d%d",&year,&month,&day);
|
|
|
|
|
|
|
|
switch(month)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:if(day==1)
|
|
|
|
|
|
|
|
printf("元旦\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:if(day==5)
|
|
|
|
|
|
|
|
printf("清明\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:if(day==1)
|
|
|
|
|
|
|
|
printf("劳动节\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:if(day==1)
|
|
|
|
|
|
|
|
printf("儿童节\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:if(day==1)
|
|
|
|
|
|
|
|
printf("建党节\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:if(day==1)
|
|
|
|
|
|
|
|
printf("建军节\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:if(day==10)
|
|
|
|
|
|
|
|
printf("教师节\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:if(day==1)
|
|
|
|
|
|
|
|
printf("国庆节\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:printf("error");
|
|
|
|
|
|
|
|
}printf("\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
|
|
|
|
printf("输入年月:");
|
|
|
|
|
|
|
|
scanf("%d%d",&y,&m);
|
|
|
|
|
|
|
|
printf(" %d年%d月\n",y,m);
|
|
|
|
|
|
|
|
printf(" 一 二 三 四 五 六 日\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("-------------操作选项-----------\n");
|
|
|
|
|
|
|
|
printf(" 1:返回菜单 \n");
|
|
|
|
|
|
|
|
printf(" 2:退出程序 \n");
|
|
|
|
|
|
|
|
printf(" 3:执行操作 \n");
|
|
|
|
|
|
|
|
printf("\t" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("选择要执行的操作: ");
|
|
|
|
|
|
|
|
scanf("%d",&x);
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(x==2)
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(x)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1: break;
|
|
|
|
|
|
|
|
case 3: hello();break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
printf("错误输出\n");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|