First Date
来源:互联网 发布:网络安全技术题 编辑:程序博客网 时间:2024/06/05 14:48
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-15Sample Output
1582-10-151752-09-141900-03-101923-03-01Problem 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;}
- First Date
- First Date
- hnu 12952 First Date
- UESTC 893&&uvalive 6627 First Date
- UESTC 893 First Date 计算时间
- UESTC 893 First Date 计算时间
- First Date (hnoj12952)日期计算
- first
- first
- first
- First
- first
- first
- first
- first
- First
- first
- First
- Java与C++继承中的重载,覆盖和隐藏
- group by 扩展函数之GROUPING SETS
- html小知识12
- UVa 572 油田
- git简介
- First Date
- 如何应对危机
- hnu 12948
- Boxes and Stones - UVa 12525 dp
- 易语言写dll,vc调用
- eclipse中的maven web项目报错:org/codehaus/plexus/archiver/jar/JarArchiver
- poj2190
- “赢在中国”点评人给80后年轻人的30个忠告
- iOS 开发常用宏定义