题解 | #获得月份天数#

获得月份天数

https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6

大一新生

#include <stdio.h>

int main() {
    int year,month;

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

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 18:35
简历上把1个月实习写成了3个月,会进行背调吗?
码农索隆:一个月有一个月的实习经历,三个月有三个月的实习经历
点赞 评论 收藏
分享
积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务