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

计算日期到天数转换

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

#include <stdio.h>
#include <string.h>

int main()
{
    int monthinfo[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int year, month, day;
    scanf("%d %d %d", &year, &month, &day);

    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
        monthinfo[1]++;

    int datecount = 0;
    for (int i = 0; i < month - 1; i++)
    {
        datecount += monthinfo[i];
    }
    datecount += day;
    
    printf("%d", datecount);

    return 0;
}

全部评论

相关推荐

14 1 评论
分享
牛客网
牛客企业服务