题解
【入门】有几天
1 条题解
-
0
#include <iostream> using namespace std; bool isLeapYear(int year) { if (year % 400 == 0) return true; if (year % 100 == 0) return false; if (year % 4 == 0) return true; return false; } int main() { int year, month; cin >> year >> month; int days = 0; if (month == 2) { if (isLeapYear(year)) { days = 29; } else { days = 28; } } else if (month == 4 || month == 6 || month == 9 || month == 11) { days = 30; } else { // 其他月份:1,3,5,7,8,10,12 → 都是31天 days = 31; } cout << days << endl; return 0; }
- 1