The first few days of this year? - cattle-off

Title Description

Enter the year, month, date, day of the calculation is the first few days of the year.

Enter a description:

Comprising three INTEGER (1 <= Y <= 3000), January (1 <= M <= 12), day (1 <= D <= 31).

Output Description:

May enter multiple sets of test data for each set of test data, output an integer representing the Input-year, month, day corresponding to the first few days of the year.

Example 1

Entry

1990 9 20
2000 5 1

Export

263
122

Problem-solving ideas

First day of each month the number stored in the array, it can accumulate.

Determine whether a leap year, and if the month is greater than 2, you need to add one day.

Finally, add the date.

 1 #include <stdio.h>
 2 int main()
 3 {
 4     int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
 5     int y,m,d;
 6     int sum = 0;
 7     while(scanf("%d%d%d",&y,&m,&d)!=EOF)
 8     {
 9         for(int i = 0;i < m-1;i++)
10         {
11             sum = month[i]+sum;
12         }
13         if(y%4==0&&y%100!=0&&m>2) sum++;
14         printf("%d",sum+d);
15         
16     }
17 }

 

Guess you like

Origin www.cnblogs.com/jiashun/p/newcode12.html