中國有句俗語叫做“三天打魚兩天曬網”。
某人從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;
}