Source: POJ (Coursera statement: The exercises completed on POJ will not count against the final results of Coursera. )
Note: Total time limit: 1000ms memory limit: 65536kB
Description
The Beetle's "a Day" and "Tomorrow Never Knows" are popular, if you tell you A day in the life, will it really be tomorrow never knows? believe that after learning this is not a problem, and now come to realize it 。
Reads a date in a format of YYYY-MM-DD (that is, the year-month-day), outputting the date of the day next to this date. You can assume that the date entered is not earlier than 1600-01-01, or later than 2999-12-30.
input
Enter only one row, formatted as a yyyy-mm-dd date.
Output
The output is also only one row, formatted as a YYYY-MM-DD date
Sample Input
2010-07-05
Sample Output
2010-07-06
Tips
The standard for leap years:
(1) The average year can be divisible by 4 and not divisible by 100 for leap years. (For example, 2004 is a leap year, 1901 is not a leap)
Earth Revolution
(2) century can be divisible by 400 is a leap year. (as 2000 is a leap year, 1100 is not a leap year)
The input statement scanf ("%d-%d-%d", &y,&m,&d) can be stored for years, months, and days. The output statement is formatted like printf ("%d-%02d-%02d\n", Year,month,day).
1#include <iostream>2#include <stdio.h>3 intIsleapyear (intYear );4 intMain ()5 {6 inty,m,d;7 intYear,month,day;8 intMonthcarrysave=0;9 intYearcarrysave=0;Tenscanf"%d-%d-%d",&y,&m,&d); One if(m==1|| m==3|| m==5|| m==7|| m==8|| m==Ten|| m== A){ A if(d== to){ -day=1; -Monthcarrysave=1; the } - ElseDay=d+1; - } - Else { + if(m==2){ - if(d== -){ + if(Isleapyear (y)) { Aday=1; atMonthcarrysave=1; - } - Else{ -Day=d+1; - } - } in Else if(d== in){ -day=1; toMonthcarrysave=1; + } - Else{ theDay=d+1; * } $ }Panax Notoginseng Else{ - if(d== -){ theday=1; +Monthcarrysave=1; A } the Else { +Day=d+1; - } $ } $ } -month=m+Monthcarrysave; - if(month> A){ theMonth=1; -Yearcarrysave=1;Wuyi } theyear=y+Yearcarrysave; -printf"%d-%02d-%02d\n", year,month,day); Wu return 0; - } About intIsleapyear (intYear ) $ { - if(year%4==0&&year% -!=0|| year% -==0) - return 1; - Else return 0; A}
POJ C Programming Advanced programming problem #4:tomorrow never knows?