c语言第八周练兵区

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(
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我不会起名字呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值