[Of PTA] calculated the number of days 7-19 (15 minutes)

7-19 calculate the number (15 points) days of
this question requires the preparation of program calculates a certain period of a day is the day of the mid-year.

Input format:
Enter the date given in the format "yyyy / mm / dd" (i.e., "year / month / day") in a row. Note: Criterion leap year is the year of the year divisible by 4 but not divisible by 100, or divisible by 400. Leap year February has 29 days.

Output Format:
In line output date is the first few days of the year.

Sample Input 1:
2009/03/02

Output Example 1:
61 is

Sample Input 2:
2000/03/02

Output Sample 2:
62 is

#include<stdio.h>
int main()
{
    int y,m,d,leapyear,day;
    scanf("%d/%d/%d",&y,&m,&d);
    leapyear=(y%4 == 0 && y%100 != 0) || (y%400 == 0);
    switch(m)
    {
    case 1:day=d;break;
    case 2:day=31+d;break;
    case 3:day=59+leapyear+d;break;
    case 4:day=90+leapyear+d;break;
    case 5:day=120+leapyear+d;break;
    case 6:day=151+leapyear+d;break;
    case 7:day=181+leapyear+d;break;
    case 8:day=212+leapyear+d;break;
    case 9:day=243+leapyear+d;break;
    case 10:day=273+leapyear+d;break;
    case 11:day=304+leapyear+d;break;
    case 12:day=334+leapyear+d;break;
    }
    printf("%d",day);
    return 0;
}
Published 48 original articles · won praise 0 · Views 324

Guess you like

Origin blog.csdn.net/weixin_46399138/article/details/105368667