hnu 12952 First Date

First Date
Time Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KB
Total submit users: 77, Accepted users: 44
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

讲述两种日历的记录方法  两种方法的差异在于闰年的判断方法 

前一种方法只要整除4就是闰年  第二种方法 就是当整除100的时候判断是否正常400

然后现在要将前一种日历的记录方法转换为第二种 因为第一种方法中闰年计算多了 就多算了天数

转换为第二种之后现在的日期要往后推

就是计算出多算了几个闰年就可以了  这里要注意 如果现在的时间的年份是整除100的 且月份超过了2  这一天也是多算的

转换日子的过程中要判断是否跨月  是否跨年   模拟这个过程就可以了

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>

#define eps 1e-8
#define op operator
#define MOD  10009
#define MAXN  100100

#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define FOV(i,a,b)  for(int i=a;i>=b;i--)
#define REP(i,a,b)  for(int i=a;i<b;i++)
#define REV(i,a,b)  for(int i=a-1;i>=b;i--)
#define MEM(a,x)    memset(a,x,sizeof a)
#define ll __int64

using namespace std;

int mm[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
int y,m,d;

int isleap(int yy)
{
    int flag=0;
    if(yy%100==0)
    {
        if(yy%400==0)  flag=1;
    }
    else
    {
        if(yy%4==0)  flag=1;
    }
    return flag;
}

void print()
{
    int sum=0;
    for(int i=100; i<y; i+=100)
    {
        if(i%400)  sum++;
    }
    if(m>2&&(y%100)==0)
    {
        if(y%400)  sum++;
    }
    sum-=1;
//    cout<<sum<<endl;
    //跨月  跨年
    int flag=0;//是否是闰年
    flag=isleap(y);
    int x=sum-(mm[flag][m-1]-d);
    if(x<=0)
    {
        d+=sum;
        if(d<10)
        {
            if(m<10)
            {
                printf("%d-0%d-0%d\n",y,m,d);
                return;
            }
            else
            {
                printf("%d-%d-0%d\n",y,m,d);
                return;
            }
        }
        else
        {
            if(m<10)
            {
                printf("%d-0%d-%d\n",y,m,d);
                return;
            }
            else
            {
                printf("%d-%d-%d\n",y,m,d);
                return;
            }
        }
    }
    sum-=(mm[flag][m-1]-d);
    d=0;
    while(x>0)
    {
        m++;
        if(m==13)
        {
            m=1; y++;
            flag=isleap(y);
        }
        x=sum-mm[flag][m-1];
        if(x<=0)
        {
            d+=sum;
            if(d<10)
            {
                if(m<10)
                {
                    printf("%d-0%d-0%d\n",y,m,d);
                    return;
                }
                else
                {
                    printf("%d-%d-0%d\n",y,m,d);
                    return;
                }
            }
            else
            {
                if(m<10)
                {
                    printf("%d-0%d-%d\n",y,m,d);
                    return;
                }
                else
                {
                    printf("%d-%d-%d\n",y,m,d);
                    return;
                }
            }
//            x=0;
        }
        sum-=(mm[flag][m-1]-d);
    }
}

int main()
{
//freopen("ceshi.txt","r",stdin);

    while(scanf("%d-%d-%d\n",&y,&m,&d)!=EOF)
    {
        print();
    }
    return 0;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值