18-year-old birthday
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 23411 Accepted Submission (s): 7494
problem DescriptionGardon's 18 birthday is coming, he is certainly very happy, but he suddenly thought of a problem, is not everyone from birth, to reach the 18-year-old birthday when the number of days passed is the same? It doesn't seem to be all that, so he wants to ask you to calculate the total number of days he and his friends have passed since they were born to their 18 birthday.
Inputa number T, followed by the T line, has a date on each line, and the format is YYYY-MM-DD. As my birthday is in 1988-03-07.
OutputT line, one number per line, indicating the number of days that the person has passed from birth to the age of 18. If this person does not have a 18 birthday, then output-1.
Sample Input
11988-03-07
Sample Output
6574
AuthorGardon
Ideas:
first of all, the year after she was born, it is 18 years old that year between the number of days, then she was born that you year and he 18 years of the year just can make up a whole year, but do not know is leap years or common year, so to conduct a discussion: first according to common year calculation, then the month analysis, to determine whether add 1, If the year of birth is January or February, then add 1, if 18 years old that month than February plus 1!
Code:
#include <stdio.h>int main () {int y,m,d;int n,i,j,k,s;scanf ("%d", &n), while (n--) {scanf ("%d-%d-%d", &y, &M,&D); for (i=y+1,s=0;i<y+18;i++) {k=365;if (i%4==0&&i%100!=0| | i%400==0) k=366;s+=k;} S+=365;if (m<=2&& (y%4==0&&y%100!=0) | | y%400==0) s+=1;if (m>2&& (y+18)%4==0&& (y+18)%100!=0) | | (y+18)%400==0) s+=1;if (((y%4==0&&y%100!=0) | | y%400==0) && ((y+18)%4!=0| | (y+18)%100==0) && (y+18)%400!=0) (&&m==2&&d==29) printf (" -1\n"); else printf ("%d\n" , s);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 1201-18 Birthday