中国有句俗语叫做“三天打鱼两天晒网”。
某人从1990年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是打鱼还是晒网。
#include<stdio.h>
int judgeLeapYear(int year){//润年判断,0不是,1是
if((!(year%4)&&(year%100))||!(year%400))
return 1;
else
return 0;
}
void daysHandle(int year,int month,int day,int *days){
int num[]={31,28,31,30,31,30,31,31,30,31,30,31};
int beginYear,beginMonth;
if(judgeLeapYear(year))//判断输入的年份是否为闰年,进而确定二月数值
num[1]++;
for(beginYear=1990;beginYear<year;beginYear++){//加年
if(judgeLeapYear(beginYear))
*days+=366;
else
*days+=365;
}
for(beginMonth=0;beginMonth<(month-1);beginMonth++) {//加月
*days+=num[beginMonth];
}
*days+=day;//加日
}
void judge(int days){//判断打鱼还是晒网
int temp=days%5;
printf("在距离1990年的第%d天该人是在:",days);
if(temp==4||temp==0)
printf("晒网");
else
printf("打鱼");
}
int main(){
int year,month,day,days=0;
puts("请输入年月日(中间以空格隔开):");
scanf("%d%d%d",&year,&month,&day);
daysHandle(year,month,day,&days);
judge(days);
return 0;
}