慕课第八周_练兵区_第一题

1 三天打渔两天晒网(4分) 题目内容:中国有句俗语叫“三天打鱼两天晒网”,某人从1990年1月1日起开始“三天打鱼两天晒网”,即工作三天,然后再休息两天。问这个人在以后的某一天中是在工作还是在休息。从键盘任意输入一天,编程判断他是在工作还是在休息,如果是在工作,则输出:He is working,如果是在休息,则输出:He is having a rest,如果输入的年份小于1990或者输入的月份和日期不合法,则输出:Invalid input。
输入格式: “%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>
#define SIZE 13
int isor(int year,int month,int day);
void output(int sum);
int main()
{
int year, month, day,sum;
scanf("%4d-%2d-%2d", &year,& month,& day);
if(year < 1990 || month>12 || month < 1 || day>31 || day < 1)
{
printf(“Invalid input\n”);
}
else
{
sum=isor(year,month,day);
output(sum);
}
return 0;

}
int isor(int year,int month,int day)
{
int y,count=0,m=0;
int a[SIZE]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int n,i,sum=0,number;
for(y=1990;y<=year;y++)
{
if(y%40 && y%100!=0 || y%4000)
{
count++;
}
m++;
}
n=month-1;
for(i=0;i<=n;i++)
{
sum+=a[i];
}
number=day-1;
sum+=number;
if(count!=0)
{
if(month>2)
sum=sum+(m-1)*365+count;
else
sum=sum+(m-1)*365+count-1;
}
else
sum=sum+(m-1)*365+count;
return sum;
}
void output(int sum)
{
int c;
c=sum%5;
switch©
{
case 1:
case 2:
case 0:

	printf("He is working\n");
	break;		
case 3:
case 4:
	printf("He is having a rest\n" );
	break;
}

}

你是我如梦如幻的画,
想把你写进我的代码;
我日夜思念的脸庞啊,
码出初见你时的模样。
by皇棠
to那年夏天

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值