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

计算日期到天数转换

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

#include <iostream>
using namespace std;

int main() {
    int a, b;
    int day;
    int arr1[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    int arr2[12]={31,29,31,30,31,30,31,31,30,31,30,31};

    while (cin >> a >> b) { // 注意 while 处理多个 case
        cin>>day;
        int sum=0;
        if((a%4==0&&a%100!=0)||(a%400==0))
        {
            for(int i=0;i<b-1;i++)//闰年
            {
                sum+=arr2[i];
            }
            sum+=day;
        }
        else
        {
            for(int i=0;i<b-1;i++)//非闰年
            {
                sum+=arr1[i];
            }
            sum+=day;
        }
        cout << sum << endl;
        
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 14:23
steelhead:你回的有问题,让人感觉你就是来学习的
点赞 评论 收藏
分享
qq乃乃好喝到咩噗茶:院校后面加上211标签,放大加粗,招呼语也写上211
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 13:47
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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