[GESP202303 一级] 每月天数题解

· · 题解

这题非常简单,我就不废话了,自己看注释。 语言(C++):

#include<bits/stdc++.h>
using namespace std;
int main(){
    int year,month;
    cin>>year>>month;
    if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){//先判断月是否为大月
        cout<<31;//就输出31
    }else{
        if(month==4||month==6||month==9||month==11){//如果是小月
            cout<<30;//输出30
  }else{//如果都不是if((month==2&&year%4==0&&year%100!=0)||year%400==0){//(month==2&&year%4==0&&year%100!=0)这里要加括号,不然会错一个点
                cout<<29;//输出29;
            }else{
                cout<<28;否则输出28
            }
        }
    }

    return 0;
}