C语言趣味例题

三天打鱼两天晒网问题

复制代码
 1 #include <iostream>
 2 using namespace std;
 3 class Date{
 4     public:
 5         int year,month,day;
 6         Date(int y,int m,int d):year(y),month(m),day(d){
 7         }
 8 };
 9 bool runyear(int x)
10 {
11     if((x%400==0) || (x%4==0 && x%100!=0))
12     {
13         return true;
14     }
15     else
16     {
17         return false;
18     }
19 }
20 int count(class Date c)
21 {
22     int total=0;
23     int permonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
24     for(int year=1990;year<c.year;year++)
25     {
26         if(runyear(year))
27         {
28             total+=366;
29         }
30         else
31         {
32             total+=365;
33         }
34     }
35     if(runyear(c.year))
36     {
37         permonth[2]+=1;
38     }
39     for(int month=0;month<c.month;month++)
40     {
41         total+=permonth[month];
42     }
43     total+=c.day;
44     return total%5;
45 }
46 int main()
47 {
48     int y,m,d;
49     cin>>y>>m>>d;
50     Date c(y,m,d);
51     if(count(c)==4 || count(c)==0)
52     {
53         cout<<"shaiwang"<<endl;
54     }
55     else
56     {
57         cout<<"dayu"<<endl;
58     }
59     return 0;
60 } 
复制代码

 

posted @   新晋软工小白  阅读(61)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示