文章

6

粉丝

553

获赞

9

访问

38.1k

头像
Brief
P1051 中南大学机试题
发布于2020年7月18日 22:10
阅读数 7.9k

#include <stdio.h>

int main(){

    int y,m,d;

    //init other month
    int month[12]={31,0,31,30,31,30,31,31,30,31,30,31};


    while(~scanf("%d %d %d",&y,&m,&d)){
        
        int sum=0;

        //init Feb.
        if(y%4==0&&y%100!=0||y%400==0) month[1]=29;
        else month[1]=28;
        

       //Filter
        if(y<1||m<1||m>12||d>month[m-1]||d<1){
            printf("Input error!\n");
            continue;
        }
        

        //calc day
        for(int i=0;i<m-1;i++){

            sum+=month[i];
        }

        sum+=d;
            
        printf("%d\n",sum);
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发