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.

167 lines
5.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<windows.h>
/*判断是否为闰年*/
int R(int year)
{
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
return 1;
else
return 0;
}
/*判断该月多少天*/
int max_day(int year, int month)
{
int day[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (R(year) == 1)
day[1] = 29;
return day[month - 1];
}
/*判断该天是这一年第几天*/
int total_day(int year, int month, int day)
{
int sum = 0;
int i = 1;
for (i = 1; i < month; i++)
sum += max_day(year, i);
sum += day;
return sum;
}
/*判断该天是星期几*/
int weekday(int year, int month, int day)
{
int count;
count = (year - 1) + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + total_day(year, month, day);
count %= 7;
return count;
}
/*显示该天是星期几*/
void display_week(int year, int month, int day)
{
int count;
count = weekday(year, month, day);
switch (count)
{
case 0:printf("\t%d年%d月%d日是星期天\n", year, month, day); break;
case 1:printf("\t%d年%d月%d日是星期一\n", year, month, day); break;
case 2:printf("\t%d年%d月%d日是星期二\n", year, month, day); break;
case 3:printf("\t%d年%d月%d日是星期三\n", year, month, day); break;
case 4:printf("\t%d年%d月%d日是星期四\n", year, month, day); break;
case 5:printf("\t%d年%d月%d日是星期五\n", year, month, day); break;
case 6:printf("\t%d年%d月%d日是星期六\n", year, month, day); break;
}
}
/*展示月份表格*/
void display_month(int year, int month, int day)
{
int i = 0, j = 1;
int week, max;
week = weekday(year, month, 1);
max = max_day(year, month);
printf("\n\t\t\t **%d年%d月**",year,month);
printf("\n");
printf("\n\t\t\t\t\t\t\t\n\n");
for (i = 0; i < week; i++)
printf("\t");
for (j = 1; j <= max; j++)
{
printf("\t%d",j);
if (i % 7 == 6)
printf("\n\n");
i++;
}
printf("\n\n");
}
/*判断是否为公历节日*/
void display_festival(int year,int month,int day)
{
int ff;
if(month==1&&day==1)ff=22;
else if(month==2&&day==14)ff=1;
else if(month==3&&day==8)ff=2;
else if(month==3&&day==12)ff=3;
else if(month==3&&day==15)ff=4;
else if(month==4&&day==1)ff=5;
else if(month==5&&day==1)ff=6;
else if(month==5&&day==12)ff=7;
else if(month==5&&day==31)ff=8;
else if(month==6&&day==1)ff=9;
else if(month==6&&day==5)ff=10;
else if(month==6&&day==6)ff=11;
else if(month==6&&day==26)ff=12;
else if(month==7&&day==1)ff=13;
else if(month==7&&day==7)ff=14;
else if(month==8&&day==1)ff=15;
else if(month==9&&day==10)ff=16;
else if(month==9&&day==20)ff=17;
else if(month==10&&day==1)ff=18;
else if(month==11&&day==8)ff=19;
else if(month==12&&day==1)ff=20;
else if(month==12&&day==25)ff=21;
else ff=0;
switch(ff)
{
case 22:printf("\t%d年%d月%d日是元旦节\n", year, month, day); break;
case 1:printf("\t%d年%d月%d日是情人节\n", year, month, day); break;
case 2:printf("\t%d年%d月%d日是国际妇女节 \n", year, month, day); break;
case 3:printf("\t%d年%d月%d日是中国植树节\n", year, month, day); break;
case 4:printf("\t%d年%d月%d日是世界消费者权益日\n", year, month, day); break;
case 5:printf("\t%d年%d月%d日是愚人节 \n", year, month, day); break;
case 6:printf("\t%d年%d月%d日是劳动节\n", year, month, day); break;
case 7:printf("\t%d年%d月%d日是国际护士节\n", year, month, day); break;
case 8:printf("\t%d年%d月%d日是世界无烟日\n", year, month, day); break;
case 9:printf("\t%d年%d月%d日是国际儿童节 \n", year, month, day); break;
case 10:printf("\t%d年%d月%d日是世界环境日\n", year, month, day); break;
case 11:printf("\t%d年%d月%d日是世界爱眼日\n", year, month, day); break;
case 12:printf("\t%d年%d月%d日是国际禁毒日\n", year, month, day); break;
case 13:printf("\t%d年%d月%d日是中国共产党的生日\n", year, month, day); break;
case 14:printf("\t%d年%d月%d日是中国抗日战争纪念日\n", year, month, day); break;
case 15:printf("\t%d年%d月%d日是中国人民解放军建军纪念日\n", year, month, day); break;
case 16:printf("\t%d年%d月%d日是中国教师节\n", year, month, day); break;
case 17:printf("\t%d年%d月%d日是全国爱牙日\n", year, month, day); break;
case 18:printf("\t%d年%d月%d日是中华人民共和国国庆节\n", year, month, day); break;
case 19:printf("\t%d年%d月%d日是记者节\n", year, month, day); break;
case 20:printf("\t%d年%d月%d日是全国艾滋病日\n", year, month, day); break;
case 21:printf("\t%d年%d月%d日是圣诞节\n", year, month, day); break;
default:printf("\t今天不是啥节日");break;
}
}
/*判断是否这个日子已经过去*/
int rrr(int year, int month, int day)
{
int qqq,www,eee,x;
printf("今天是哪一天:");
scanf("%d%d%d",&qqq,&www,&eee);
if(qqq>year)
x=1;
else if(qqq==year&&www>month)
x=1;
else if(qqq==year&&www==month&&eee>=day)
x=1;
else x=0;
switch(x)
{
case 0:printf("这一天是过去的一天\n") ;break;
case 1:printf("这一天是未过去的一天\n");break;
}
return 0;
}
/*主函数*/
int main()
{
int year, month, day;
printf("请输入你要查询的日期(yyyy-mm-dd)");
scanf("%d%d%d", &year, &month, &day);
if (month<1||month>12||day<1||day>31)
{
printf("你输错了");
return -1;
}
printf(" %d年%d月%d日是这一年的第%d天\n", year, month, day, total_day(year, month, day));
display_week(year, month, day);
display_festival(year,month,day);
display_month(year, month, day);
rrr(year, month, day);
system("pause");
return 0;
}