HJ73 计算日期到天数转换

计算日期到天数转换

https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded?tpId=37&&tqId=21296&rp=1&ru=/ta/huawei&qru=/ta/huawei/question-ranking

参考 https://www.nowcoder.com/profile/365362210/codeBookDetail?submissionId=118703040

闰年:四年一闰,百年不闰,四百年再闰

代码

#include <stdio.h>

int isleapyear(int year)
{
    if(0 == year%4)
    {
        if(0 == year%100 && 0 != year%400)
            return 0;
        else
            return 1;
    }
    else
        return 0;
}

int main()
{
    int daynum_of_leapyear[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
    int daynum_of_commonyear[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
    
    int year,month,day;
    scanf("%d %d %d", &year, &month, &day);
    
    int daynum = 0;
    if(1 == isleapyear(year))
    {
        for(int i =0; i<month-1; i++)
        {
            daynum += daynum_of_leapyear[i];
        }
    }
    else
    {
        for(int i =0; i<month-1; i++)
        {
            daynum += daynum_of_commonyear[i];
        }
    }
    
    daynum += day;
    printf("%d",daynum);
    return 0;
}
全部评论

相关推荐

狠赚笔第一人:学计算机自己不努力怪大环境?我大一就拿到了美团大厂的offer,好好看看自己有没有努力查看图片
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务