题解 | #计算天数#

计算天数

https://www.nowcoder.com/practice/3dc98d482fa84c1ab84384773cce1468

#include <iostream>

using namespace std;
int main(){
    int daytab[2][13]={
        {0,31,28,31,30,31,30,31,31,30,31,30,31},
        {0,31,29,31,30,31,30,31,31,30,31,30,31}
        };
    int year,month,day;
    int eat;
    cin>>eat;   // 我太懒了,直接把输入数据量吃掉,懒得改下面了
    while(cin>>year>>month>>day){
        int today=1,yearFlag=0,m=1,d=1;
        if(year%400==0||(year%100!=0&&year%4==0)) yearFlag=1;
        while(m!=month||d!=day){
            today++;
            d++;
            if(d>daytab[yearFlag][m]){
                m++;
                d=1;
            }
        }
        cout<<today<<endl;

    }

}

全部评论

相关推荐

shtdbb_:还不错,没有让你做了笔试再挂你
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务