1878: 蛤玮准备礼物
Time Limit: 1 Sec
Memory Limit: 128 MB
Submit: 595
Solved: 75
Submit Status Web Board
Description
蛤玮的妹子要过生日了,经过千挑万选,蛤玮决定给妹子买一盒水彩铅笔,然而卖多少个才合适呢.机智的蛤玮决定数一数今天是妹子出生的第多少天,然后就买那么多根铅笔.
给出蛤玮妹子的生日和今天的日期,求蛤玮一共需要买多少.
注意:生日当天算第0天.
Input
T(1<=T<=1000),表示数据组数.
每组数据一行y1,m1,d1,y2,m2,d2,其中y1,m1,d1表示妹子生日的年月日,y2,m2,d2表示蛤玮所在时空的当前天的年月日.
(1900<=y<=1000000, 1<=m<=12, 1<=d<=当月应有天数).输入保证当前天在妹子生日之后.
Output
Sample Input
2
1995 10 24 1995 10 25
1996 1 9 1996 3 7
Sample Output
HINT
Source
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<algorithm>
using namespace std;
#define N 1010000
#define INF 0x3f3f3f3f
int yearday[N];
int IsLeap(int year)
{
return ((year%4==0&&year%100!=0) || year%400==0);
}
int main()
{
int T, y1, m1, d1, y2, m2, d2, sum;
int tab[2][13]={{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
int leap;
yearday[1899]=0;
for(int i=1900; i<=1000000; i++)
yearday[i]=yearday[i-1]+(IsLeap(i)==1 ? 366 : 365);
scanf("%d", &T);
while(T--)
{
scanf("%d%d%d%d%d%d", &y1, &m1, &d1, &y2, &m2, &d2);
sum=0;
if(y1==y2)
{
leap=IsLeap(y1);
for(int i=m1+1; i<m2; i++)
sum+=tab[leap][i];
if(m1<m2)
{
sum+=tab[leap][m1]-d1;
sum+=d2;
}
else
sum+=d2-d1;
printf("%d\n", sum);
}
else
{
leap=IsLeap(y1);
for(int i=m1+1; i<=12; i++)
sum+=tab[leap][i];
sum+=tab[leap][m1]-d1;
leap=IsLeap(y2);
for(int i=1; i<m2; i++)
sum+=tab[leap][i];
sum+=d2;
sum+=yearday[y2-1]-yearday[y1];
printf("%d\n", sum);
}
}
return 0;
}