自己写的。C语言。题解 | #计算日期到天数转换#

计算日期到天数转换

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

#include<stdio.h>
int main() {
    int year, month, day, sum = 0;
    char IsLeapYear = 0;
    scanf("%d %d %d", &year, &month, &day);
    if (year % 100 == 0) {
        if (year % 400 == 0) {
            IsLeapYear = 1;
        }
    } else {
        if (year % 4 == 0) {
            IsLeapYear = 1;
        }
    }
    if (month == 2) {
        sum += 31;
    } else if (month == 3) {
        sum += 59;
    } else if (month == 4) {
        sum += 90;
    } else if (month == 5) {
        sum += 120;
    } else if (month == 6) {
        sum += 151;
    } else if (month == 7) {
        sum += 181;
    } else if (month == 8) {
        sum += 212;
    } else if (month == 9) {
        sum += 243;
    } else if (month == 10) {
        sum += 273;
    } else if (month == 11) {
        sum += 304;
    } else if (month == 12) {
        sum += 334;
    }
    if (IsLeapYear == 1 && month > 2) {
        sum += 1;
    }
    sum += day;
    printf("%d\n", sum);
    return 0;
}

全部评论

相关推荐

10-25 23:12
门头沟学院 Java
点赞 评论 收藏
分享
vegetable_more_exercise:1-1.5万,没错啊,最少是1人民币,在区间内
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务