Hdu 1201 18-year-old birthday day Simulation

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.