1 /*
 2 日期格式为YYYYMMDD 
 3 */
 4 #include<cstdio>
 5 #include<algorithm> 
 6 using namespace std;
 7 
 8 int isLeap(int y){
 9     return (y%400==0)||(y%4==0&&y%100!=0);
10 }
11 
12 int main(){
13     int time,cnt;
14     int y,m,d;
15     int month[14][2] = {{0,0},{31,31},{28,29},{31,31},{30,30},{31,31},{30,30},{31,31},{31,31},{30,30},{31,31},{30,30},{31,31}};
16     scanf("%d%d",&time,&cnt);
17     y = time/10000;
18     m = time/100%100;
19     d = time%100;
20     int pb = (int)(1.0*cnt/abs(cnt));
21     for(int i=1;i<=abs(cnt);i++){
22         d = d + pb;
23         if(d == month[m][isLeap(y)]+1 || d == 0){
24             m = m + pb;
25             if(pb>0)
26                 d = 1;
27             else if(m!=0)
28                 d = month[m][isLeap(y)];
29         }
30         if(m == 13 || m == 0){
31             y = y + pb;
32             if(pb>0)
33                 m = 1;
34             else
35                 m = 12;
36             if(m == 12 && pb<0)
37                 d = month[m][isLeap(y)];
38         }
39     }
40     printf("%04d年%02d月%02d日",y,m,d);
41     return 0;
42 }

 

版权声明:本文为javier2018原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/javier2018/p/8530999.html