题解 | #今年的第几天#

今年的第几天

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

#include <iostream>
using namespace std;

int main() {
    int year,month,day,run;
    int yy[2][12]={
        {31,28,31,30,31,30,31,31,30,31,30,31},
        {31,29,31,30,31,30,31,31,30,31,30,31}
    };
    while(cin>>year>>month>>day){
        if((year%4==0&&year%100!=0)||(year%400==0))run=1;
        else run=0;
        int number=0;
        int i=0;
        while(month>i+1){
            number+=yy[run][i];
            i++;
        }
        number+=day;
        cout<<number;
    }

}

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务