中国有句俗语叫 “ 三天打鱼两天晒网 ” 。某人从 1990 年 1 月 1 日起开始 “ 三天打鱼两天晒网 ” , 问这个人在以后的某一天中是 “ 打鱼 ” 还是 “ 晒网 ” 。
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int M[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31};
int Y[4] = {0, 0, 1, 0};
int i;
int leapyear, sum;
int year, month, day;
printf("输入需要查询的年月日:");
scanf("%d%d%d", &year, &month, &day);
if (year < 1990 || month > 12 || day > 31) {
printf("错误的输入....");
exit(-1);
}
if ((year % 4 == 0 && year % 100 == 0) || year % 400 == 0) {
leapyear = 1;
if (month == 2 && day > 29) {
printf("错误的输入....");
exit(-1);
}
} else {
leapyear = 0;
if (month == 2 && day > 28) {
printf("错误的输入....");
exit(-1);
}
}
sum = 0;
for (i=1990; i<year; ++i) {
if (Y[(i-1990) % 4] == 0 )
sum += 365;
else
sum += 366;
}
if (leapyear == 0)
M[1] = 29;
for (i=1; i<month; ++i)
sum += M[i-1];
sum += day;
sum = sum % 5;
if (sum >=1 && sum <=3)
printf("打渔\n");
else
printf("晒网\n");
return 0;
}