题解 | #HJ73 计算日期到天数转换#

计算日期到天数转换

http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded

#include <stdio.h>

int main() {
    int daysPerMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int y, m, d, s;
    while (scanf("%d %d %d", &y, &m, &d) != EOF) {
        if ((y%4==0 && y%100 != 0) || (y%400 == 0)) {
            daysPerMonth[1] = 29;
        } else {
            daysPerMonth[1] = 28;
        }
        s = 0;
        for (int i = 0; i < m-1; i++) {
            s += daysPerMonth[i];
        }
        s += d;
        printf("%d\n", s);
    }
    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
2
分享
牛客网
牛客企业服务