18th birthday
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 10990 Accepted Submission (s): 3504
Problem Description
Gardon's 18-year-old birthday is coming soon. Of course, he is very happy, but he suddenly thought of a question: is it true that everyone has gone through the same number of days from birth to 18-year-old birthday? This does not seem to be the case, so he wants to ask you to calculate the total number of days that he and his friends have passed since their birth to their 18-year-old birthday.
Input
A number T, followed by a date in each line of T, in the format of YYYY-MM-DD. For example, my birthday is 1988-03-07.
Output
T indicates the number of days that the person passes from his birth to his/her 18-year-old birthday. If this person is not 18 years old,-1 is output.
Sample Input
1
1988-03-07
Sample Output
6574
Author
Gardon
Ideas:
Find the key to the question and try to reduce the complexity.
[Cpp]
# Include <stdio. h>
Int main ()
{
Int cas, I, nian, yue, ri;
Scanf ("% d", & cas );
While (cas --)
{
Int sum = 0, flag = 0;
Scanf ("% d-% d", & nian, & yue, & ri );
If (nian % 400 = 0 | (nian % 4 = 0 & nian % 100! = 0) & (nian + 18) % 400! = 0 & (nian + 18) % 4! = 0 | (nian + 18) % 100 = 0) // the current year is a leap year, and 18 years is not a leap year.
{
If (yue = 2 & ri = 29) {printf ("-1 \ n"); continue ;}
}
Sum = 365*18;
For (I = nian + 1; I <nian + 18; I ++)
If (I % 400 = 0 | (I % 4 = 0 & I % 100! = 0 ))
Sum + = 1;
If (nian % 400 = 0 | (nian % 4 = 0 & nian % 100! = 0 ))
{
If (yue = 1 | (yue = 2 & ri <29) sum + = 1;
}
If (nian + 18) % 400 = 0 | (nian + 18) % 4 = 0 & (nian + 18) % 100! = 0 ))
{
If (yue> = 3) sum + = 1;
}
Printf ("% d \ n", sum );
}
Return 0;
}