Today is HRBUST2019 freshmen match race, Xiao Zhao and Chen happily came to the playing field.
At this time, Chen suddenly thought of the day before yesterday, the teacher said to check 10 days after a big operation, Xiao Zhou asked: "how Android work 10 days after the preparation of the?."
Then Xiao Zhou asked: "Today is 10 days in November 2019 No. 16, the last of 10 days to say today count on only 8 days, but where's the 10 days you want to Shane?!!."
Chen: "yes yes yes, you are powerful, you are considered prospective, only eight days, then I ask you, 50 days is the date?."
Small Zhou Zixin replied: "Today is the 16th, plus 50 is 66, minus 30 days this month left 36 days, minus 31 days next month to five days left, so the answer is January 5 next year, how? did not count it wrong! "
"Another," Chen continued to ask, "100 days after it? 200 days after it?"
Then Xiao Zhou was asked a series of questions to the trouble, said: "You wait, and so I wrote a program, whatever you ask."
Xiao Zhou then come to you, you help him write the program.
Entry
Topic multiple sets of test data, to the end of file processing.
Each test line following an integer n, n Calculate the number is a few days. (-10000 <= n <= 10000).
Export
Each set of test data output "YYYY MM DD" represents the month, MM YYYY DD date.
Sample input Copy
0 1 -1
Sample output Copy
2019 11 16 2019 11 17 2019 11 15
prompt
Note that filled four year, month and daily two leading zeros padded with leading 0.
Subject to the effect: that is to say to you today's date (eg: November 26, 2019) n ask you forward or backward (-10000 <= n <= 10000) day is that day in January that year
AC Code :( might have with you long-winded, Great God do not spray)
#include <iostream> using namespace std; int main(){ int y,m,d,dmax; int d1; y=2019,m=11,d=16; while(~scanf("%d",&d1)){ if(d1>0){ for(int i=1;i<=d1;i++){ switch(m){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: dmax=31; break; case 4: case 6: case 9: case 11: dmax=30; break; } if(m==2){ if(y%400==0||y%100!=0&&y%4==0){ dmax=29; }else{ dmax=28; } } if(d<dmax){ d++; }else if(d==dmax&&m<12){ m=m+1; d=1; }else if(m==12&&d==31){ y=y+1; m=1; d=1; } } } else if(d1<0){ d1=-d1; for(int i=d1;i>=1;i--){ switch(m){ case 1: case 2: case 4: case 6: case 8: case 9: case 11: dmax=31; break; case 5: case 7: case 10: case 12: dmax=30; break; } if(m==3){ if(y%400==0||y%100!=0&&y%4==0){ dmax=29; }else{ dmax=28; } } if(d>1){ d--; }else if(d==1&&m>1){ m=m-1; d=dmax; }else if(m==1&&d==1){ y=y-1; m=12; d=dmax; } } } printf("%04d %02d %02d\n",y,m,d); y=2019,m=11,d=16; } return 0; }
Example 2:
Enter
only one line, were read into the Y, M, D (representing year, month, day), date absolutely legitimate.
(1900 <= Y <= 2008,1 <= M <= 12,1 <= D <= 31)
only one line that ZCQ teacher birthday ten thousandth days after the date in the format "YMD".
(Note that between the date of connection with a line)
1979. 4 16
sample output the Copy
2006-9-1
#include <the iostream> the using namespace STD; int main () { int Y, m, D, Dmax; CIN >> >> m >> Y D; for ( int I = . 1 ; I <= 10000 ; I ++) { / / the arbitrary number 10000 to become any date days Switch (m) { Case . 1 : Case . 3 : Case . 5 : Case . 7 : Case . 8 : Case 10 : Case 12 is : Dmax=31; break; case 4: case 6: case 9: case 11: dmax=30; break; } if(m==2){ if(y%400==0||y%100!=0&&y%4==0){ dmax=29; }else{ dmax=28; } } if(d<dmax){ d++; }else if(d==dmax&&m<12){ m=m+1; d=1; }else if(m==12&&d==31){ y=y+1; m=1; d=1; } } cout<<y<<"-"<<m<<"-"<<d; return 0; }