The total number of days elapsed 18th birthday _ June 30, 2019 byte beat Kong _ _ R & D program written the original title

Reprinted to: https://blog.csdn.net/qq_41181881/article/details/79221895

Problem Description

Gardon's 18th birthday is coming, he of course very happy, but he suddenly thought of a problem, is not the number of days when everyone from birth, to reach 18th birthday passes are the same? Does not seem all so, so he would like to ask you to help calculate what he and several of his friends from birth to reach the total number of days elapsed 18th birthday, let's compare him good.

Input

A number T, T row behind each row has a date format YYYY-MM-DD. As my birthday is 1988-03-07.

Output

T lines, each a number representing the number of days the person from birth to 18th birthday elapsed. If this person is not 18th birthday, on output -1.
 
 Sample Input
1 1988-03-07
 
Sample Output
6574
 

Problem-solving ideas

        A year is a leap year leap year 365 days or 366 days, if the birthday is after February, this year is not a leap year does not matter, but is now under a year is not a leap year relationship. Code is as follows (including comments)
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int n,i,year,month,day,t,y;
 5     scanf("%d",&n);
 6     for(i=1;i<=n;i++)
 7     {
 8         scanf("%d-%d-%d",&year,&month,&day);
 9         if(month==2&&day==29)//4年过一次生日
10         {
11             printf("-1\n" );
 12 is          }
 13 is          the else 
14          {
 15              T = 0 ;
 16              IF (month The> = . 3 ) // greater than February, after one year, the number of days determined one year old days 
. 17              {
 18 is                  for (Y = year + . 1 ; Y < + year = 18 is ; Y ++ )
 . 19                  {
 20 is                      IF ((Y% . 4 == 0 && Y% 100 ! = 0 ) || Y% 400 == 0 )
 21 is                      {
 22 is                         T = T + 366 ;
 23 is                      }
 24   
25                      the else 
26 is                      {
 27                          T = T + 365 ;
 28                      }
 29                  }
 30              }
 31 is              the else  IF (month The <= 2 ) // less February, the year the number of days determined number of days a year-old 
32              {
 33 is                  for (Y = year; Y <= + year . 17 ; Y ++ )
 34 is                  {
 35                      IF ((Y% . 4==0&&y%100!=0)||y%400==0)
36                     {
37                         t=t+366;
38                     }
39                     else
40                     {
41                         t=t+365;
42                     }
43                 }
44             }
45             printf("%d\n",t);
46         }
47  
48     }
49 }

 

Guess you like

Origin www.cnblogs.com/yichengming/p/11129892.html