address: http://acm.hdu.edu.cn/showproblem.php?pid=1201
Problem Description
Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达18岁生日所经过的总天数,让他好来比较一下。
Input
一个数T,后面T行每行有一个日期,格式是YYYY-MM-DD。如我的生日是1988-03-07。
Output
T行,每行一个数,表示此人从出生到18岁生日所经过的天数。如果这个人没有18岁生日,就输出-1。
Sample Input
1
1988-03-07
Sample Output
6574
code:
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
bool f(int a)
{
if (a%4==0&&a%100!=0||a%400==0)
return true;
else
return false;
}
int main()
{
int N;
cin>>N;
//getchar();
while (N--)
{
int a,b,c;
char x,y;
int m;
int i;
int ans = 365*18;
scanf ("%d%c%d%c%d",&a,&x,&b,&y,&c);
//getchar();
for (i=1;i<=17;i++)
{
m = a+i;
if (f(m))
ans++;
}
if (f(a)&&b==2&&c==29)
{
cout<<-1<<endl;
continue;
}
else if (f(a)&&f(a+18))
ans++;
else if (f(a)&&!f(a+18))
{
if (b<=2&&c<=28)
ans++;
}
else if (!f(a)&&f(a+18))
{
if (b>=3)
ans++;
}
cout<<ans<<endl;
}
return 0;
}