hrbust Calendar 基础细节题。计算时间必须记住了。。

Calendar
Time Limit: 1000 MSMemory Limit: 131072 K
Total Submit: 17(7 users)Total Accepted: 4(4 users)Rating: Special Judge: No
Description

Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:

Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.

Input

In the first line, the is a integer T (1T100), which means there T cases of this problem.

In every case, the input has two format:

1):yyyy1:mm1:dd1 yyyy2:mm2:dd2

2):yyyy1:mm1:dd1 day

If the format is the 1) type, your task is to calculate how many days are between yyyy1:mm1:dd1 and yyyy2:mm2:dd2.

Others, your task is output the date after the date yyyy1:mm1:dd1, and the days between them is day. The format of the answer is yyyy:mm:dd.

1000  yyyy  9999 and yyyy:mm:dd is a legal date.

0day, we can ensure the answer of the second type is satisfied with 1000  yyyy  9999.

Output
For every case, display the answer of this question per line.
Sample Input

4

1900:01:01 2038:12:31

1900:01:01 50768

1996:03:09 1991:11:12

1991:11:12 1579

Sample Output

50768

2038:12:31

1579

1996:03:09

Source
"尚学堂杯"哈尔滨理工大学第六届程序设计竞赛
#include<stdio.h>
#include<string.h>
#include<math.h>
#define ll long long
using namespace std;
int judge(int y)
{
    if(y%400==0) return 1;
    if(y%4==0&&y%100!=0) return 1;
    return 0;
}
int yue1[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
int yue2[13]= {0,31,29,31,30,31,30,31,31,30,31,30,31};
ll js(int y,int m,int d)
{
    ll tmp=(y-1)/4-(y-1)/100+(y-1)/400;
    tmp+=(y-1)*365;
    for(int i=1; i<m; i++)
    {
        if(i==2&&judge(y))
            tmp++;
        tmp+=yue1[i];
    }
    tmp+=d;
    return tmp;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char a[1003],b[1003];
        scanf("%s %s",a,b);
        int n1=0,n2=0,y1=0,y2=0,r1=0,r2=0,day=0;
        int l=strlen(b);
        int f=0;
        for(int i=0; i<l; i++)
        {
            if(b[i]==':')
            {
                f=1;
                break;
            }
        }
        int la=strlen(a);
        int ma=0;
        for(int i=0; i<la; i++)
        {
            if(a[i]==':')
            {
                ma++;
                continue;
            }
            if(ma==0)
            {
                n1=(n1*10)+a[i]-'0';
            }
            else if(ma==1)
            {
                y1=(y1*10)+a[i]-'0';
            }
            else if(ma==2)
            {
                r1=(r1*10)+a[i]-'0';
            }
        }
        long long day1=js(n1,y1,r1);
        if(f)
        {
            int lb=strlen(b);
            int mb=0;
            for(int i=0; i<lb; i++)
            {
                if(b[i]==':')
                {
                    mb++;
                    continue;
                }
                if(mb==0)
                {
                    n2=(n2*10)+b[i]-'0';
                }
                else if(mb==1)
                {
                    y2=(y2*10)+b[i]-'0';
                }
                else if(mb==2)
                {
                    r2=(r2*10)+b[i]-'0';
                }
            }
            long long day2=js(n2,y2,r2);
            long long  ans=day2-day1;
            if(ans<0)
                ans=-ans;
            printf("%lld\n",ans);
        }
        else
        {
            int lb=strlen(b);
            int day2=0;
            for(int i=0;i<lb;i++)
            {
                day2=day2*10+b[i]-'0';
            }
            //printf("%d\n",day2);
            while(day2--)
            {
                r1++;
                if(judge(n1))
                {
                    if(r1>yue2[y1])
                    {
                        y1++;
                        r1=1;
                    }
                    if(y1>12)
                    {
                        y1=1;
                        n1++;
                    }
                }
                else
                {
                    if(r1>yue1[y1])
                    {
                        y1++;
                        r1=1;
                    }
                    if(y1==13)
                    {
                        y1=1;
                        n1++;
                    }
                }
            }printf("%4d:%02d:%02d\n",n1,y1,r1);
        }
    }
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值