Calendar--CodeForces - 304B (前缀+审题)

                                                    Calendar

                                                        Time limit  2000 ms     Memory limit  262144 kB

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

一个简单题,可以直接暴力求解,但是容易绕迷

也有巧法,其实 只需要分别求出来所给的两个时间与边间时间 1900-1-1 的时间差,然后再作差即可!

可以使用前缀和的方法,预处理出年和月的天数差(打个表)然后直接拿来使用!

注意编码的时候一定细心细心再细心

#include<cstdio>
#include<string>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int inf=0x3f3f3f3f;

bool check(int x){
	if(x%400==0||x%4==0&&x%100!=0)
		return true;
	return false;
} 

int s[2100];
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int day[13];
void init(){
	int sum=0;
	for(int i=1900;i<=2040;i++){
		sum+=check(i)?366:365;
		s[i]=sum;
	}
	for(int i=1;i<13;i++)
		day[i]=day[i-1]+month[i];
}

int y,m,d;
int yy,mm,dd;

int main()
{
	init();
	scanf("%d:%d:%d",&y,&m,&d);
	scanf("%d:%d:%d",&yy,&mm,&dd);
	
	int d1=s[y-1]+day[m-1]+d-1;
	if(check(y)&&m>=3)
		d1++;
		
	int d2=s[yy-1]+day[mm-1]+dd-1;
	if(check(yy)&&mm>=3)
		d2++;
		
	cout<<abs(d1-d2)<<endl;
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值