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.

174 lines
6.2 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<stdlib.h>
#include<string.h>
char*month_str[]={"January","February","March","April","May","June","July","August","September","Octoer","November","December"};
char* week[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
char* festivals[] = {"1,1","2,14","3,8","3,12","3,15","4,1","4,5","5,1","5,4", "6,1","7,1","8,1","9,10","10,1","12,25"};
int IsLeapYear(int year) /*判断是否是闰年*/
{
if((year%4==0&&year%100!=0)|| (year%400==0)) //这⾥是判断是否是闰年的
return 1; //如果是闰年就返回值1
else
return 0;//不是的话返回0
}
int month_day(int year,int month) //这个函数⽤来判断 这年的月分有多少天的
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(IsLeapYear(year)&&month==2) /*判断是否是闰年如果是闰年⽽且这个⽉是2⽉那这个月有29天*/
return 29;
else
return(mon_day[month-1]); }
int DaySearch(int year,int month,int day) /*这个函数是计算输入的日期对应的星期*/
{
int c=0;
float s;
int m; for(m=1;m<month;m++)
c=c+month_day(year,m); //这是计算输入的月分的累计天数
c=c+day; //该⽇期在这⼀年中是第几天
s=year-1+(int)(year-1)/4+(int )(year-1)/100+(int)(year-1)/400-40+c; /*这是计算⽇期对应的星期公式,这是网上查的*/
return ((int)s%7); //与上语句同属计算日期对应的星期
}
int YearMonth(int year,int month)
{ int temp;int j;
printf("\n\n%s(%d)\n",month_str[month-1],month); //输出⽉分名称
printf("SA MO TU WE TH FR SA \n");
temp=DaySearch(year,month,1);/*这个函数是计算输⼊的日期对应的星期*/
for(j=1;j<=month_day(year,month)+temp;j++)
{
if(j-temp<=0) printf(" ");
else if(j-temp<10)
printf("%2d ",j-temp);
else
printf("%2d ",j-temp);
if(j%7==0) printf("\n");
}
return 0;
}
int PrintAllYear(int year)/*这个函数是⽤用来输出全年年的 ⽇日历*/
{
int temp;
int i,j;
printf("---------------The Calander Of %d---------------\n",year);
for(i=1;i<=12;i++)
{
printf("\n\n%s(%d)\n",month_str[i-1],i); //输出月分名称
printf("SA MO TU WE TH FR SA \n");
temp=DaySearch(year,i,1);/*这个函数是计算输⼊的日期对应的星期*/
for(j=1;j<=month_day(year,i)+temp;j++)
{
if(j-temp<=0)
printf(" ");
else if(j-temp<10)
printf("%2d ",j-temp);
else
printf("%2d ",j-temp);
if(j%7==0)
printf("\n");
}
}
return 0;
}
int testDate1(int month,int day)
{
char Date[] = {"month,day"};
//sprintf(Date, "%d,%d", month, day);
for (int i = 0; i <15; i++)
if (strcmp(Date, festivals[i])!=0)
{ printf("");
break;
}
return 0;
}
int main()
{
int option,da;
char ch;
int year,month,day;
printf("---------------欢迎使用旺氏日历---------------\n");
while(1)
{
printf("\n请输入你想查询的内容:"); //⽤来提示选择执行功能
printf("\n1,星期(具体年月日的星期)"); //⽤来计算这一天是星期⼏
printf("\n2,月历"); //输出月历
printf("\n3,年历"); //输出全年的日历
printf("\n4,节日查询");//输出该天是否为节日
printf("\n5,退出\n");//选择退出程序
scanf("%d",&option);
switch(option) //⽤用来选择执⾏
{
case 1:/*当为1时进⾏相应运算*/
while(1)
{
printf("\n请输入年月日(例如2019,10,1):"); //提示输入
scanf("%d,%d,%d",&year,&month,&day); //读⼊数据
da=DaySearch(year,month,day); //调⽤DaySearch()函数来计算是星期几
printf("\n您查询的%d,%d,%d是%s",year,month,day,week[da]);
printf("\n您还想继续查询吗?(如果继续请直接输入否则请输入N返回主菜单)");
fflush(stdin); //刷新输⼊入缓冲区
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 2: /*当为2时进行相应运算*/
while(1)
{
printf("\n请输入你想查询的年月(例如2019,1)");
scanf("%d,%d",&year,&month);
YearMonth(year,month);
printf("\n您还想继续查询吗?(如果继续请直接输入否则请输入N返回主菜单)");
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 3: /*当为3时运⾏行行相应的运算*/
while(1)
{
printf("\n请输入您想查询的年份(仅限于1940-2040)");
scanf("%d",&year);
PrintAllYear(year);
printf("\n您还想继续查询吗?(如果继续请直接输入否则请输入N返回主菜单)?");
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 4:/*当为4时运行相应的运算*/
while(1)
{
printf("\n请输入你想查询的日期(例如11,1)");
scanf("%d,%d",&month,&day);
testDate1(month,day);//是节⽇则输出是,不是则无输出
printf("\n您还想继续查询吗(如果继续请直接输⼊否则请输入N返回主菜单)?");
fflush(stdin);
scanf("%c",&ch);
if(ch=='N'||ch=='n')
break;
}
break;
case 5:/*当为4时运行相应的运算*/
while(1)
{
printf("您确认吗?(如果继续请直接输入否则请输入Y退出该程序)");
fflush(stdin);
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
{
printf ("\n感谢您的使用!^_^");
exit(1);
}
break;
default:
printf("\nError:Sorry,there is no this service now!\n");
break;
}
}
}
return 0;
}