题解 | #今年的第几天?#

今年的第几天?

https://www.nowcoder.com/practice/ae7e58fe24b14d1386e13e7d70eaf04d

#include <iostream>
using namespace std;

bool is_run(int year){
    if(year%4==0&&year%100!=0||year%400==0) return true;
    return false;
}
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,12};


int main() {
    int y,m,d;
    while(cin>>y>>m>>d){
        int res=0;
        if(is_run(y)){
            month[2]++;
            for(int i=1;i<m;i++){
                res+=month[i];
            }
            res+=d;
        }else{
            for(int i=1;i<m;i++){
                res+=month[i];
            }
            res+=d;
        }
        cout<<res<<endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

刘湘_passion:出国旅游?那就小心你的腰子咯
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务