题解
【入门】判断某年某月的天数
1 条题解
-
0
#include <iostream> using namespace std; int main() { int year, month; cin >> year >> month; // 判断是否为闰年 bool isLeap = false; if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { isLeap = true; } int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (month == 2 && isLeap) { cout << 29 << endl; } else { cout << days[month] << endl; } return 0; }
- 1