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

计算日期到天数转换

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

#include <iostream>
using namespace std;

int main() {
    int year, month, day;
    cin>>year>>month>>day;
    int res;
    int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){
        days[2] = 29;
    }
    days[month] = day;
    while(month > 0){
        res += days[month];
        month--;
    }
    cout<<res;
}

全部评论

相关推荐

哈哈哈,你是老六:百度去年裁员分评不好,赶紧弄点红包
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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