【问题描述】
输入年份和月份,输出该月份的天数。
【输入形式】
输入一行,两个整数,分别为年份和月份。
【输出形式】
一个整数,表示该月份的天数
【样例输入】
2018 3
【样例输出】
31
#include <iostream>
using namespace std;
int calculateYear(int year,int month){
if(year%400==0||(year%100!=0&&year%4==0)){ //闰年的二月29天
if (month == 2){
return 29;
}
else{
if(month == 1||month==3||month==5||month==7||month==8||month==10||month==12){
return 31;
}
else return 30;
}
}
else {
if (month == 1||month==3||month==5||month==7||month==8||month==10||month==12){
return 31;
}
if (month == 2)return 28;
else return 30;
}
}
int main(){
int a,b;
cin>>a>>b;
int sum = calculateYear(a,b);
cout<<sum;
return 0;
}