HDU-1201-18 birthday

Source: Internet
Author: User

Question Link

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1201

This question was submitted many times during the competition, all of which were wa. The main mistake was that I did not consider the last year, the next year, that is, if the year Y + 18 is a leap year and the month m> = 3 | (M = 2 & D = 29)

The number of days is one more day.

Divided into three parts: Y + 1-> Y + 17 y + 18

Wa code

# Include <stdio. h>
Int main (void)
{
Int kk (int n );
Int T;
Int y, M, D;
Int I, J;
Int S;
Scanf ("% d", & T );
While (t --)
{
S = 0;
Scanf ("% d-% d", & Y, & M, & D );
If (kk (y) & M = 2 & D = 29)
{
If (kk (Y + 17) = 0)
{
Printf ("-1 \ n ");
Continue;
}
}
If (kk (y ))
{
If (M <= 2 & D <= 28)
S = S + 366;
Else
S = S + 365;
}
Else
S = S + 365;
For (I = Y + 1; I <Y + 17; I ++)
{
If (kk (I ))
S = S + 366;
Else
S = S + 365;
}
If (kk (Y + 17 ))
{
If (M> 2)
S = S + 366;
Else if (M = 2 & D = 29)
S = S + 366;
Else
S = S + 365;
}
Else
S = S + 365;
Printf ("% d \ n", S );
}
Return 0;
}

Int kk (int n)
{
If (N % 4 = 0)
{
If (N % 100 = 0)
{
If (N % 400 = 0)
Return 1;
Else
Return 0;
}
Else
Return 1;
}
Else
Return 0;
}

 

 

AC code

# Include <stdio. h>
Int main (void)
{
Int run (int n );
Int T, I;
Int y, M, D;
Scanf ("% d", & T );
While (t --)
{
Int S = 0;
Scanf ("% d-% d", & Y, & M, & D );
If (run (Y + 18) = 0 & M = 2 & D = 29)
{
Printf ("-1 \ n ");
Continue;
}
If (run (y) & M <= 2)
S ++;
For (I = 1; I <= 17; I ++)
{
If (run (Y + I ))
S ++;
}
If (run (Y + 18) & (M> 2 | (M = 2 & D = 29 )))
S ++;
Printf ("% d \ n", 18*365 + S );
}
Return 0;
}

Int run (int n)
{
If (N % 400 = 0 | (N % 4 = 0 & N % 100! = 0 ))
Return 1;
Return 0;
}

 

The road to the program is too long. Only perseverance and fearlessness can we climb the peak.

HDU-1201-18 birthday

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.