码迷,mamicode.com
首页 > 其他好文 > 详细

计概期末前的小小总结

时间:2020-01-04 18:15:49      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:back   题目   round   code   pre   基本   闰年   打鱼   padding   

1.日期问题

基本上是必考的

一定要注意闰年的处理!!

别忘了判断【今年】是不是闰年

题目 打鱼还是晒网  
描述
中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起开始“三天打鱼两
天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。
注意要区分闰年和不是闰年的两种情况

关于输入
输入为三个整数
按照年 月 日 输入为之后的某一天

关于输出
输出为单词
如果今天渔夫打鱼就是
fishing
如果今天晒网就是
sleeping

例子输入
1991 10 25
例子输出
fishing
 1 #include<iostream>
 2 using namespace std;
 3 bool isr(int year){
 4     if(year%4==0&&year%100!=0)
 5         return true;
 6     if(year%400==0) //世纪闰年 
 7         return true;
 8     return false; 
 9 }
10 int main(){
11     int year, month, day;
12     cin>>year>>month>>day;
13     int total = 0;
14     int leap;
15     for(int y = 1990; y < year; y++){ //先算年 
16         leap = isr(y);
17         total += 365+leap;
18     }
19     leap=isr(year);
20     for(int m = 1; m < month; m++){
21         switch(m){
22             case 2: total+=28+leap; break;
23             case 4:; case 6:; case 9:; case 11: total+=30; break;
24             default: total+=31; break;
25         }
26     }
27     total += day;
28     if(total%5==4||total%5==0) cout<<"sleeping"<<endl;
29     else cout<<"fishing"<<endl;
30     return 0;
31 } 

备注:

计概期末前的小小总结

标签:back   题目   round   code   pre   基本   闰年   打鱼   padding   

原文地址:https://www.cnblogs.com/fangziyuan/p/12149694.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!