某人三天打渔两天晒网,假设他从1990年1月1日开始打渔三天,然后晒网两天,请编程回答任意的一天他在打渔还是晒网。
输入格式:
"%4d-%2d-%2d"
输出格式:
"Invalid input" 或
"He is having a rest" 或
"He is working"
输入样例1:
2014-12-22
输出样例1:
He is working
输入样例2:
2014-12-24
输出样例2:
He is having a rest
输入样例3:
2014-12-32
输出样例3:
Invalid input
#include<stdio.h>
int main(void)
{
int year, month, date, flag = 0, year1, flag1 = 0;
int sum, sum1, temp;
scanf_s("%4d-%2d-%2d", &year, &month, &date);
if (month < 0 || month <= 12 && date < 0 || date >= 31)
{
printf("Invalid input\n");
return -1;
}
for (year1 = 1990; year1 <= year; year1++)
{
if (year1 % 4 == 0 && year1 != 0 || year1 == 0)
flag += 1;
else
flag1 += 1;
}
sum = 366 * flag + 365 * flag1;
sum1 = 0;
for (int a = 12; a >= month; a--)
{
switch (a)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12: temp = 31; break;
case 4: case 6: case 9: case 11: temp = 30; break;
case 2:
{
if (year % 4 == 0 && year%100!= 0 || year%400 == 0)
temp = 29;
else temp = 28;
}
break;
default: temp = 0;
}
sum1 += temp;
}
sum = sum - sum1 + date;
if (sum % 5 == 0 || sum % 5 == 4)
{
printf("He is having a rest!\n");
}
else
printf("He is working!\n");
return 0;
}