First Date

来源:互联网 发布:网络安全技术题 编辑:程序博客网 时间:2024/06/05 14:48

First DateTime Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KBTotal submit users: 77, Accepted users: 43Problem 12952 : No special judgementProblem description

Given the last day for which the Julian calendar is in effect for some country (expressed as a Julian date), determine the next day’s Gregorian date, i.e., the first date that uses the Gregorian calendar.


Input

For each test case, the input consists of one line containing a date in the Julian calendar, formatted as YYYY-MM-DD. This date will be no earlier than October 4, 1582, and no later than October 18, 9999. The given date represents the last day that the Julian calendar is in effect for some country.


Output

For each test case, print the first Gregorian date after the calendar transition.


Sample Input
1582-10-041752-09-021900-02-251923-02-15
Sample Output
1582-10-151752-09-141900-03-101923-03-01
Problem SourceNWERC 2013

题目大意:将J日历转换成G日历。

分析:算出G的转换需要在J日期的基础上加多少天,然后在J日期上一天一天加(便于处理月份、年份的进位)。

注意:在计算天数的时候要清楚:使G日历跑的比J日历原因是:对J是闰年但对G不是闰年的年份的2月在J中多了29号这天。


代码:

/*G题*/#include <cstdio>#include <cstring>#include <iostream>using namespace std;typedef long long LL;const int maxn = 10 + 5;struct NODE{int year, month, day;}J, G;int skip;int rule[13] = { 0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };bool leap(int x){if (x % 4 == 0){if (x % 100 != 0 || (x % 100 == 0 && x % 400 == 0))return true;}return false;}bool day_to_month(){if (G.month == 2)//2月{if (leap(G.year)){if (G.day == 29)return true;}else{if (G.day == 28)return true;}}//其他月份else if (G.day == rule[G.month])return true;return false;}void solve(){skip = (J.year - 1) / 100 / 4 * 3 + ((J.year - 1) / 100) % 4 - 1;if (J.year % 100 == 0 && J.year % 400 != 0){if (J.month > 2)skip++;if (J.month == 2 && J.day == 29){skip++;J.month = 2;J.day = 28;}}G = J;for (int i = 1; i <= skip; i++){if (day_to_month())//进月{G.month++; G.day = 1;if (G.month > 12)//进年{G.year++;G.month = 1;}}else G.day++;}}int main(){freopen("f:\\input.txt", "r", stdin);while (scanf("%d-%d-%d", &J.year, &J.month, &J.day) != EOF){solve();printf("%d-%02d-%02d\n", G.year, G.month, G.day);}return 0;}



0 0
原创粉丝点击