杭电OJ-2005

#include
int main(){
    int day,month,year;
    while(scanf("%d/%d/%d",&year,&month,&day)!=EOF){
        if(year%400==0||(year%4==0&&year%100!=0)){
            switch (month){
            case 1:
                printf("%d\n",day);
                break;
            case 2:
                printf("%d\n",day+31);
                break;
            case 3:
                printf("%d\n",day+31+29);
                break;
            case 4:
                printf("%d\n",day+31+29+31);
                break;
            case 5:
                printf("%d\n",day+30+31+29+31);
                break;
            case 6:
                printf("%d\n",day+31+30+31+29+31);
                break;
            case 7:
                printf("%d\n",day+30+31+30+31+29+31);
                break;
            case 8:
                printf("%d\n",day+31+30+31+30+31+29+31);
                break;
            case 9:
                printf("%d\n",day+31+31+30+31+30+31+29+31);
                break;
            case 10:
                printf("%d\n",day+30+31+31+30+31+30+31+29+31);
                break;
            case 11:
                printf("%d\n",day+31+30+31+31+30+31+30+31+29+31);
                break;
            case 12:
                printf("%d\n",day+30+31+30+31+31+30+31+30+31+29+31);
                break;
            }
        }
        else{
            switch (month){
            case 1:
                printf("%d\n",day);
                break;
            case 2:
                printf("%d\n",day+31);
                break;
            case 3:
                printf("%d\n",day+31+28);
                break;
            case 4:
                printf("%d\n",day+31+28+31);
                break;
            case 5:
                printf("%d\n",day+30+31+28+31);
                break;
            case 6:
                printf("%d\n",day+31+30+31+28+31);
                break;
            case 7:
                printf("%d\n",day+30+31+30+31+28+31);
                break;
            case 8:
                printf("%d\n",day+31+30+31+30+31+28+31);
                break;
            case 9:
                printf("%d\n",day+31+31+30+31+30+31+28+31);
                break;
            case 10:
                printf("%d\n",day+30+31+31+30+31+30+31+28+31);
                break;
            case 11:
                printf("%d\n",day+31+30+31+31+30+31+30+31+28+31);
                break;
            case 12:
                printf("%d\n",day+30+31+30+31+31+30+31+30+31+28+31);
                break;
            }
        }
    }
    return 0;
}

【转】网上代码参考:http://blog.sina.com.cn/s/blog_ac5ed4f3010169cl.html

你可能感兴趣的:(杭电OJ-2005)