[HDU] [2005] Which Day?

Problem Description

Loading...

Problem Analysis

This is a question about leap years. When I was solving it, my brain short-circuited on leap year determination (⊙﹏⊙)b A leap year requires being divisible by 4. But if it’s **00, it must also be divisible by 400. I got stuck on that point for quite a while…

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
int main() {
    int Y,M,D,i,n;
    int day[12]= {0,31,28,31,30,31,30,31,31,30,31,30};
    while(scanf("%d/%d/%d",&Y,&M,&D)!=EOF) {
        n=0;
        if(Y%4==0)
            day[2]=29;
        if(Y%100==0)
            if(Y%400!=0)
                day[2]= 28;
        for(i=0; i<M; i++)
            n=n+day[i];
        n=n+D;
        printf("%d\n",n);
    }
    return 0;
}

Loading...