CF 304B

B. Calendar

time limit per test : 2 seconds

memory limit per test : 256 megabytes

input : standard input

output : standard output

 

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. 

In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.

Look at the sample to understand what borders are included in the aswer.

Input

The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 ≤ yyyy ≤ 2038 and yyyy:mm:dd is a legal date).

Output

Print a single integer — the answer to the problem.

Examples

input

1900:01:01
2038:12:31

output

50768

input

1996:03:09
1991:11:12

output

1579

思路十分简单,首先把两个日期都化为整年(往小的化),然后循环,求出两个年份之间的总天数,随后多的减去,少的补上就行,看代码可以理解。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},days=0,no=0;
int x,y,z,xx,yy,zz;

inline bool is_ok(int x,int y,int z,int xx,int yy,int zz){
    if (xx!=x) return xx>x;
    if (yy!=y)return yy>=y;
    return zz>=z;
}

int main(){
    scanf("%d:%d:%d",&x,&y,&z);
    scanf("%d:%d:%d",&xx,&yy,&zz);
    if (!is_ok(x,y,z,xx,yy,zz)){
        swap(x,xx);
        swap(y,yy);
        swap(z,zz);
    }
    no+=z;
    if (y<=2) no+=month[y==2?1:0];
    else{
        for (int i=1;i<y;++i) no+=month[i];
        if ((x%4==0 && x%100!=0) || x%400==0) ++no;
    }
    cerr<<no<<endl;
    days+=zz;
    if (yy<=2) days+=month[yy==2?1:0];
    else{
        for (int i=1;i<yy;++i) days+=month[i];
        if ((xx%4==0 && xx%100!=0) || xx%400==0) ++days;
    }
    cerr<<days<<endl;
    for (int i=x;i<xx;++i)
        days+=(i%4==0 && i%100!=0) || i%400==0 ? 366 : 365;
    cerr<<days<<endl;
    cout<<days-no<<endl;
    return 0;
}
/*
 1999:12:31
 2000:02:29
 */

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值