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

计算日期到天数转换

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


#include <stdio.h>

int day_of_year(int year, int month, int day);

int main(){
    
    int year, month, day;
    int serial = 1;
    while( scanf("%d %d %d", &year, &month, &day) != EOF ){
        serial = day_of_year(year, month, day);
        printf("%d\n", serial);
    }
    
    return 0;
}

int day_of_year(int year, int month, int day)
{
    int ret = 0;
    //每个月之前的累计天数
    int LeapYear[12] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
    int NormalYear[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
    //闰年
    if( (year%4==0 && year%100 != 0) || year%400 == 0 )
        ret = LeapYear[month-1] + day;
    //平年
    else
        ret = NormalYear[month-1] + day;
    
    return ret;
}


全部评论

相关推荐

03-28 20:13
东南大学 Java
2的三次幂:第一个项目写的太简略了,可以结合业务背景写下细节,第二个太冗余了,缺乏量化指标,一眼玩具
点赞 评论 收藏
分享
03-29 17:05
门头沟学院 Java
asdasdasda...:我前段时间找工作焦虑,有几天连续熬夜熬穿了,然后心脏突然不舒服,立马躺床上睡觉了,然后第二天还是不舒服,去看医生说是心率不齐,吓得我后面天天早早睡觉,调养身体,过了好几天才好过来。所以真的,工作这些东西哪有那么重要,最多钱多一点钱少一点,降低物欲。活着才是最重要的,现在想想真的后怕
如何排解工作中的焦虑
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务