题解 | #计算天数#

计算天数

https://www.nowcoder.com/practice/3dc98d482fa84c1ab84384773cce1468

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool isleap(int year) {
    if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) {
        return true;
    }
    return false;
}

int main() {
    int year, month, day, m;
    while (scanf("%d", &m) != EOF) { // 注意 while 处理多个 case

        for (int j = 0; j < m; j++) {
            scanf("%d%d%d", &year, &month, &day);
            if (isleap(year)) {
                days[2] = 29;
            } else {
                days[2] = 28;
            }

            int count = 0;

            for (int i = 0; i < month; i++) {
                count += days[i];
            }

            count += day;
            printf("%d\n", count);

        }

    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

10-15 09:13
已编辑
天津大学 soc前端设计
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务