题解 | 今年的第几天?

今年的第几天?

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

#include <iostream>
using namespace std;
//              1 2   3  4  5  6  7  8  9 10 11 12
int arr[27]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main() {
    int year,month,day;
    while(cin>>year>>month>>day){
        if(year%400==0||(year%4==0&&year%100!=0)){
            arr[2]=29;
        }
        int sum = 0;
        for(int i=0;i<month;++i){
            sum+=arr[i];
        }
        sum+=day;
        cout<<sum<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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