题解 | #获得月份天数#

获得月份天数

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

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
    int a[7] = {1, 3, 5, 7, 8, 10, 12};
    int b[4] = {4, 6, 9, 11};
    int c = 2 ;
    int year = 0;
    int month = 0;
    while (scanf("%d %d", &year, &month) != EOF) {
        int i = 0;
        for (i = 0; i < 7; i++) {
            if (a[i] == month) {
                printf("31\n");
                break;
            }
            if (b[i] == month) {
                printf("30\n");
                break;
            }
            if (month == 2) {
                if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
                    printf("29\n");
                    break;
                } else {
                    printf("28\n");
                    break;
                }
            }

        }

    }

    return 0;
}

全部评论

相关推荐

头像
11-09 17:30
门头沟学院 Java
TYUT太摆金星:我也是,好几个华为的社招找我了
点赞 评论 收藏
分享
1 1 评论
分享
牛客网
牛客企业服务