c++

4396y 发表于 1年前 · 关联问题 计算月份的天数

include "pch.h"

include

using namespace std;

int main() {

int year, mon; int mday[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; while (cin>>year>>mon) { if (mon>12|| mon<1) { cout << "error"; continue; } //先判断是不是闰年 bool isLeap = year % 400 == 0 || (year % 100!=0 && year % 4 == 0); if (isLeap) { //是闰年 mday[2] = 29; } else { mday[2] = 28; } cout << mday[mon]; }

}