2011-12-16 03:49:11

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1201

题意:中文。

代码:

# include <stdio.h>


int IsLeap(int y){return y%4==0 && y%100!=0 || y%400==0;}
int days(int y, int m, int d)
{
int month[2][13] = {
{0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
{0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}} ;
return month[IsLeap(y)][m]+d ;
}


int main ()
{
int T, i ;
int y, m, d ;
int ans ;
scanf ("%d", &T) ;
while (T--)
{
scanf ("%d-%d-%d", &y, &m, &d) ;
if (m == 2 && d == 29 && !IsLeap(y+18))
{
puts ("-1") ;
continue ;
}
ans = 0 ;
for (i = y ; i < y+18 ; i++)
ans += IsLeap(i) ? 366 : 365 ;
ans += days(y+18, m, d) ;
ans -= days(y, m, d) ;
printf ("%d\n", ans) ;
}
return 0 ;
}