正文
增加 6 行删除 8 行
109 行未改动全部展开1101111121131141151161171189 行未改动128129130131132133134135136137138139140141142143369 行未改动全部展开513514515516517518519520521109 行未改动全部展开63163263363463563663763863964073 行未改动71471571671771871972072172234 行未改动109 行未改动全部展开int days(int y, int m) {if (m == 2) return isLeap(y) ? 29 : 28; // 2 月特判if (m == 4 || m == 6 || m == 9 || m == 11) return 30;return 31;}int main() {int date1, date2;cin >> date1 >> date2;// 取出起始年份和终止年份9 行未改动// 反过来生成月份和日期int month = Y4 * 10 + Y3;int day = Y2 * 10 + Y1;// 判断是否为真实存在的日期if (month < 1 || month > 12)continue;if (day < 1 || day > days(y, month))continue;// 拼成 8 位日期数字int date = y * 10000 + month * 100 + day;// 检查是否在给定范围内if (date >= date1 && date <= date2)ans++;}cout << ans;return 0;369 行未改动全部展开* 只有翻 `(i-1, i)` 或 `(i, i+1)`* 但 `(i-1, i)` 在之前已经处理完了* 所以 **只能翻 `(i, i+1)`**👉 这是**唯一选择**,不是“贪心拍脑袋”,而是**被迫选择**---## 三、具体做法(一步一步)109 行未改动全部展开这意味着什么?* 总数据量不大* **完全可以一条一条去判断*** 不需要任何高级数据结构(比如 Trie)---## 三、核心思路73 行未改动```---## 八、完整代码(静态数组)```cpp#include <bits/stdc++.h>using namespace std;34 行未改动109 行未改动全部展开1101111121131141151161171189 行未改动128129130131132133134135136137138139140141142143369 行未改动全部展开513514515516517518519520521109 行未改动全部展开63163263363463563663763873 行未改动71271371471571671771871972034 行未改动109 行未改动全部展开int days(int y, int m) {if (m == 2) return isLeap(y) ? 29 : 28; // 2 月特判if (m == 4 || m == 6 || m == 9 || m == 11) return 30;return 31;}int main() {int date1, date2;cin >> date1 >> date2;// 取出起始年份和终止年份9 行未改动// 反过来生成月份和日期int month = Y4 * 10 + Y3;int day = Y2 * 10 + Y1;// 判断是否为真实存在的日期if (month < 1 || month > 12)continue;if (day < 1 || day > days(y, month))continue;// 拼成 8 位日期数字int date = y * 10000 + month * 100 + day;// 检查是否在给定范围内if (date >= date1 && date <= date2)ans++;}cout << ans;return 0;369 行未改动全部展开* 只有翻 `(i-1, i)` 或 `(i, i+1)`* 但 `(i-1, i)` 在之前已经处理完了* 所以 **只能翻 `(i, i+1)`**👉 这是**唯一选择**---## 三、具体做法(一步一步)109 行未改动全部展开这意味着什么?* 总数据量不大* **完全可以一条一条去判断**---## 三、核心思路73 行未改动```---## 八、代码```cpp#include <bits/stdc++.h>using namespace std;34 行未改动