typedef struct date {
int year;
int month;
int day;
}DATE;
int countday(DATE from, DATE to);
int isLeap(int year);
int main()
{
DATE end, start;
int totaldays;
int result;
printf("请输入开始日期\n");
scanf("%d%d%d", &start.year, &start.month, &start.day);
printf("请输入结束日期\n");
scanf("%d%d%d", &end.year, &end.month, &end.day);
totaldays = countday(start, end);
result = totaldays % 5;
if(result > 0 && result < 4)
puts("今天打鱼");
else
puts("今天晒网");
return 0;
}
int isLeap(int year)
{
if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
return 1;
return 0;
}
int countday(DATE from, DATE to)
{
int perMonth[13]={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int result = 0, i;
if (isLeap(from.year))
perMonth[2] = 29;
int t = 12;
if (from.year == to.year) //同一年
t = to.month - 1;
for(i = from.month; i <= t; i++) { //开始的那年的月份直接加到12月
result += perMonth[i];
}
result -= from.day;
perMonth[2] = 28;
for (i = from.year + 1; i <= to.year - 1; i++) //判断中间间隔年的润平
{
if (isLeap(i))result += 366;
else
result += 365;
}
if(isLeap(to.year))
perMonth[2] = 29;
if (from.year != to.year)
for(i = 1; i <= to.month - 1; i++) { //把终点月-1加上,不算当月
result += perMonth[i];
}
result += to.day;//将当月多的几天算进去
return result;
}