B. Calendar



time limit per test



memory limit per test



input



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.



CF 304B(Calendar-一段时间的日期)_i++


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



1900 ≤ yyyy ≤ 2038



Output



Print a single integer — the answer to the problem.



Sample test(s)



input



1900:01:01 2038:12:31



output



50768



input



1996:03:09 1991:11:12



output



1579


直接模拟,要考虑同一年,同年同月,同年同月同日(0),后面的日期靠前等情况



#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define Forp(x) for(int p=pre[x];p;p=next[p])
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int is_l(int y)
{
if (y%4==0&&y%100!=0) return 366;
if (y%400==0) return 366;return 365;
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int y1,m1,d1,y2,m2,d2;
scanf("%d:%d:%d",&y1,&m1,&d1);
scanf("%d:%d:%d",&y2,&m2,&d2);
if (y1>y2||(y1==y2&&m1>m2)||(y1==y2&&m1==m2&&d1>d2)) swap(y1,y2),swap(m1,m2),swap(d1,d2);
int tot=0;
Fork(i,y1+1,y2-1) tot+=is_l(i);
if (y1^y2)
{
if (m1<2) tot+=is_l(y1)==366?29:28;
if (m2>2) tot+=is_l(y2)==366?29:28;
Fork(i,m1+1,12) if (i!=2) tot+=a[i];
Fork(i,1,m2-1) if (i!=2) tot+=a[i];
tot+=d2;
tot+=a[m1]-d1+1;
if (m1==2&&is_l(y1)==366) tot++;
if (tot) tot--;
}
else
{
if (m1^m2)
{
if (is_l(y1)==366) a[2]=29;
Fork(i,m1+1,m2-1) tot+=a[i];
tot+=d2;
tot+=a[m1]-d1+1;
tot--;
}
else tot=d2-d1;
}
cout<<tot<<endl;

return 0;
}