First Date

First Date
Time Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KB
Total submit users: 77, Accepted users: 43
Problem 12952 : No special judgement
Problem 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-04
1752-09-02
1900-02-25
1923-02-15
Sample Output
1582-10-15
1752-09-14
1900-03-10
1923-03-01
Problem Source
NWERC 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值