C语言趣味例题

发布时间 2023-05-09 21:22:41作者: 新晋软工小白

三天打鱼两天晒网问题

 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 }