编程题#4:Tomorrow never knows?
来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩。)
注意: 总时间限制: 1000ms 内存限制: 65536kB
描述
甲壳虫的《A day in the life》和《Tomorrow never knows》脍炙人口,如果告诉你a day in the life,真的会是tomorrow never knows?相信学了计概之后这个不会是难题,现在就来实现吧。
读入一个格式为yyyy-mm-dd的日期(即年-月-日),输出这个日期下一天的日期。可以假定输入的日期不早于1600-01-01,也不晚于2999-12-30。
输入
输入仅一行,格式为yyyy-mm-dd的日期。
输出
输出也仅一行,格式为yyyy-mm-dd的日期
样例输入
2010-07-05
样例输出
2010-07-06
1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 int isLeapYear(int); 5 int main() { 6 int year, month, day; 7 scanf("%d-%d-%d", &year, &month, &day); 8 9 int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 10 if (isLeapYear(year)) 11 days[2] = 29; 12 13 if (day == days[month]) { 14 day = 1; 15 if (month == 12) { 16 month = 1; 17 ++year; 18 } else { 19 ++month; 20 } 21 } 22 else { 23 ++day; 24 } 25 26 printf("%d-%02d-%02d", year, month, day); 27 return 0; 28 } 29 30 int isLeapYear(int year) { 31 if (year % 4 == 0 && year % 100 != 0 || 32 year % 400 == 0) 33 return 1; 34 else 35 return 0; 36 }