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

计算日期到天数转换

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

#include <stdio.h>


int main() {
   int year = 0;
   int month = 0;
   int day = 0;
   
   //平年1~11月总天数
   int arr[] = {0, 31, 31+28, 31*2 +28, 31*3+28-1,31*4+28-1, 31*5+28-2,
                  31*6+28-2, 31*7+28-2, 31*8+28-3, 31*9+28-3, 31*10 +28-4};
   while(scanf("%d %d %d",&year, &month,&day) ==3)
   {
     int sum =0;
     sum = arr[month-1] + day;
     //闰年,2月份以后总天数都加1
     if ((month > 2) && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))
        sum++;
     printf("%d\n",sum);
   }
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 17:10
什么素质,我请问呢,要掉小珍珠了。。。又憋屈又生气
苍蓝星上艾露:给它们能的,一群dinner牛马挥刀向更弱者罢了。我写的开源求职AI co-pilot工具,优化你的简历,找到你匹配的岗位,定制你的简历,并让你做好面试准备https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
zzzzhz:兄弟你先猛猛投简历至少三百家,能约到面试就去面。最近可以速成智能小车,智慧家居烂大街的项目,不需要自己写,只需要把里面的代码讲解看明白就行。把其中涉及到的八股文都拿出来单独背一下,我去年找工作就一个智能小车智慧家居找了10k差不多。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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