题解 | #今年的第几天?#

今年的第几天?

https://www.nowcoder.com/practice/ae7e58fe24b14d1386e13e7d70eaf04d

#include <stdio.h>
#define bool int
#define true 1
#define false 0
int days(int flag, int month) {
    int Day[2][13] = {
        {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
        {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
    };
    return Day[flag][month];
}
bool isRun(int year) {
    if ((year % 4 == 0 & year % 100 != 0) || (year % 400 == 0)) {
        return true;
    }
    return false;
}

int main() {
    int flag = 0; //flag是1的时候代表是闰年
    int year, month, day;
    int sum = 0;
    while (scanf("%d %d %d", &year, &month,
                 &day) != EOF) { // 注意 while 处理多个 case
        if (isRun(year)) {
            flag = 1;
        }
        for (int i = 0; i < month; ++i) {
            sum += days(flag,i);
        }
        sum += day;
        printf("%d\n", sum);
    }
    return 0;
}

全部评论

相关推荐

zzzilik:四个月实习做了3个项目不觉得很假吗,真没必要写这么多吧我感觉挑点核心的重点写一下我感觉会好点
你的简历改到第几版了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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