#include<stdio.h>
typedef struct{
int year,month,day;
}Data; //创建日期的结构体
void input(Data *p) //数据获取
{
int data;int permonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
printf("请输入年月日,无需空格")
scanf("%d",&data);
int day=data%100;
data=data/100;
int month=data%100;
int year=data/100;
if((year<2010)||(month<1||month>12)||(month==2&&(year%4!=0||year%400!=0)&&day>=29)||(day>permonth[month]))
//判断数据的合法性:1.月数在1~12且年数大于2010 2.闰年的二月才有29天 3.每月的天数都要和实际情况对应
{
printf("输入日期错误,请重新输入
");
input(p);
}
else{
p->day=day;p->month=month;p->year=year;
}
}
void init_data(Data *p) //初始化
{
p->day=0;
p->month=0;
p->year=0;
}
bool Run_nian(int year) //判断闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return true;
else
return false;
}
void Count(Data *p,int *sum) //计算结果
{
int permonth[13]={31,28,31,30,31,30,31,31,30,31,30,31};
int total = 0;
for(int year=2010;year<p->year;++year)
{
if(Run_nian(p->year))
{
total+=366;
}
else
{
total+=365;
}
}
if(Run_nian(p->year))
{
permonth[1]+=1;
}
for(int i=1;i<p->month;++i)
{
total+=permonth[i];
}
total+=p->day;
*sum = total;
}
int main()
{
Data p;
int sum;
init_data(&p);
input(&p);
Count(&p,&sum);
if(sum%5==4||sum%5==0) //取余
{
printf("今天晒网");
}
else
{
printf("今天打渔");
}
return 0;
}