hnu 12952 First Date

来源:互联网 发布:centos git服务器 编辑:程序博客网 时间:2024/06/06 10:48

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

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

前一种方法只要整除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 __int64using 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