CODE[VS] 2692 小明过生日

题目描述 Description

今天是小明的生日,请问下一个生日在什么时候.格式:年 月 日。

 

输入描述 Input Description

小明的生日

输出描述 Output Description

下一个小明的生日

 

样例输入 Sample Input

2013 2 13

样例输出 Sample Output

2014 2 13

 

数据范围及提示 Data Size & Hint

int范围,灰常阴险滴~~

 

我感觉不是int范围阴险。

是题目阴险。

 

像这种一看就会,看起来非常简单的题目最坑。

 

这个题就是要注意考虑到闰年的问题。

 

下面是一份zz的代码。

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<cstring>
 6 using namespace std;
 7 
 8 int a,b,c;
 9 
10 int main()
11 {
12     scanf("%d%d%d",&a,&b,&c);
13     if(b!=2||(b==2&&c!=28&&c!=29))
14     {
15         printf("%d %d %d",a+1,b,c);
16         return 0;
17     }
18     else if(c==29)
19     {
20         printf("%d 2 28",a+1);
21         return 0;
22     }
23     else 
24     {
25         if(((a+1)%4==0&&(a+1)%100!=0)||(a+1)%400==0)
26         {
27             printf("%d 2 29",a+1);
28         }
29         else printf("%d 2 28",a+1);
30         return 0;
31     }
32     return 0;
33 }
考虑是考虑到了,但是考虑得有些问题啊。。

 

 

33分zz,,无语。

 

下面看ac代码,

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<cstring>
 6 using namespace std;
 7 
 8 int a,b,c;
 9 
10 int main()
11 {
12     scanf("%d%d%d",&a,&b,&c);
13     if(b!=2||(b==2&&c!=28&&c!=29))
14     {
15         printf("%d %d %d",a+1,b,c);
16         return 0;
17     }
18     else if(c==29)
19     {
20         if((a+4)%100==0) printf("%d 2 29",a+8); //就这儿,
21         else printf("%d 2 29",a+4);
22         return 0;
23     }
24     else 
25     {
26         if(((a+1)%4==0&&(a+1)%100!=0)||(a+1)%400==0)
27         {
28             printf("%d 2 29",a+1);
29         }
30         else printf("%d 2 28",a+1);
31         return 0;
32     }
33     return 0;
34 }
就变了一点点,应该能理解

 

 

 

 

 

 

 

posted @ 2018-06-10 06:50  孟东行#  阅读(266)  评论(0编辑  收藏  举报