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