First Date
来源:互联网 发布:王者荣耀网络延迟460 编辑:程序博客网 时间:2024/05/17 02:44
First DateTime Limit: 3000ms, Special Time Limit:7500ms,Memory Limit:65536KBTotal submit users: 81, Accepted users:52Problem 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.
InputFor 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.
OutputFor each test case, print the first Gregorian date after the calendar transition.
Sample Input1582-10-041752-09-021900-02-251923-02-15Sample Output
1582-10-151752-09-141900-03-101923-03-01Problem SourceNWERC 2013
/*
题目:F:First Date
链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12952&courseid=280
题意:J 历规则:能被4整除为闰年 G 历规则:能被4整除但不能被100整除为闰年,或者能被400整除也为闰年。 给出 J 历的日期 求对应 G 历的日期
思路:求出给的年份的前一年两种日历相差的天数x,然后计算给出日期的年份过去的天数y,总天数z=x+y,然后将总天数z分给给出的年份。
感想:比赛时看四个小时的题目就是没看懂,英语实在太差。赛后知道题意后做了,一开始由于最后一年需要特殊处理而且情况比较复杂也容易糊涂所以一直WA。最后改了处理的方法,基本上不需要去怎么特殊处理,也很容易懂,所以才贴出来。这里我是按天分下去的还可以优化下按月分下去。
*/
#include<cstdio>#include<cmath>#include<cstring>#include<iostream>#include<iterator>#include<string>#include<vector>#include<queue>#include<stack>#include<list>#include<set>#include<map>#include<algorithm>using namespace std;#define LL long long#define inf 1<<29int day[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // 不是闰年int day1[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // 闰年int fun(int x){int a = 0, b = 0;a = x / 4 - 1582 / 4;b = (x / 4 - x / 100 + x / 400) - (1582 / 4 - 1582 / 100 + 1582 / 400);return a - b + 11;}int fun1(int a, int b, int c){int x = 0;if (a % 4 == 0) // a是闰年{for (int i = 1; i < b; i++) x += day1[i];x += c;}else //a不是闰年{for (int i = 1; i < b; i++) x += day[i];x += c;}return x;}int main(){int a, b, c;while (scanf("%d-%d-%d", &a, &b, &c) != EOF){int x = 0, y = 0;x = fun(a - 1); // 前 a-1 年产生的日期差y = fun1(a, b, c); // 求出 a 年过去了的天数x += y;b = 1; c = 0;for (int i = 1; i <= x; i++) // 按 G 历将天数分给a年{if ((!(a % 4) && (a % 100)) || !(a % 400)) // 闰年{if (c == day1[b]){if (b == 12) ++a, b = 1, c = 1;else ++b,c = 1;}else c++;}else // 不是闰年{if (c == day[b]){if (b == 12) ++a, b = 1, c = 1;else ++b,c = 1;}else c++;}}printf("%d-%02d-%02d\n", a, b, c);}return 0;}
0 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
- hdu1025 Constructing Roads In JGShining's Kingdom
- Ubuntu server版更新系统时间
- #define的其他用法
- 进程和线程
- cocos2dx-sprite的用法
- First Date
- RelativeLayout常用属性介绍
- cocos2dx之音乐滑动开关
- 【我的安卓开发之路】一日目:创建工程,进入xml
- 树状数组
- bzoj 1721: [Usaco2006 Mar]Ski Lift 缆车支柱
- hdu2795-Billboard(经典线段树)
- developer.biao.daily.20140901
- C C++ TDD 相关书籍推荐