The subject is a careful question to consider various situations
#include <stdio.h>
int pan (int n)
{
if (n%400==0| | (n%4==0&&n%100!=0))
return 1;
else return 0;
}
int main ()
{
int t;
scanf ("%d", &t);
while (t--)
{
int day,mon,year,sum=0,i;
scanf ("%d-%d-%d", &year,&mon,&day);
if (Pan (year) ==1&&day==29&&pan (year+18) ==0)
{
printf (" -1\n");
Continue
}
sum=365*18;//by common year first.
for (int i=year+1;i<year+18;i++)//Calculate how many years
{
if (pan (i) ==1) sum+=1;
}
if (Pan (year) ==1&& (mon==1| | (mon==2&&day<29))) sum+=1;//birthday that year is run year and in January or before 29
if (Pan (year+18) ==1&& (mon>=3)) SUM+=1;//18 year's birthday is after March and is a year of embellish
printf ("%d\n", sum);
}
return 0;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hduoj 18-year-old birthday topic 1201