三天打渔两天晒网

某人三天打渔两天晒网,假设他从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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值