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>
int count(int y,int m,int d);
int main()
{
int year,month,day,s;
scanf("%4d-%2d-%2d",&year,&month,&day);
if(year<1990||month>12||month<0||day>31||day<0)
printf("Invalid input");
else{
s=count(year,month,day);
if(s)
printf("He is working");
else
printf("He is having a rest");
}
return 0;
}
int count(int y,int m,int d){
int d1=0,d2=0,d3=0,d4=0;
int year1,year2,count=0,sum;
int a[13]={
0,31,28,31,30,31,30,31,31,30,31,30,31};
if(y%4==0&&y%100!=0||y%400==0){
year1=366;
a[2]=29;
count++;
}
else{
year2=365;
}
d1=(y-1990-count)*year2;
d2=d1+count*year1;
for(int i=0;i<m;i++){
d3+=a[i];
}
d4=d;
sum=d2+d3+d4;
if(sum%5<=3&&sum%5>=1)
return 1;
else
return 0;
}
2 统计用户输入(4分)
题目内容:从键盘读取用户输入直到遇到#字符,编写程序统计读取的空格数目、读取的换行符数目以及读取的所有其他字符数目。(要求用getchar()输入字符)
程序运行结果示例1:
Please input a string end by #:
abc def↙
jklm op↙
zkm #↙
space: 3,newline: 2,others: 15
程序运行结果示例2:
Please input a string end by #:
hello friend!#↙
space: 1,newline: 0,others: 12
输入提示信息:“Please input a string end by #:\n”
输入格式: getchar()
输出格式: “space: %d,newline: %d,others: %d\n”
#include <stdio.h>
int main()
{
char ch;
int space,newline,others;
space=0;
newline=0;
others=0;
printf("Please input a string end by #:\n");
while(