题目信息
解题思路
枚举月和日,判断后四位翻转过来的八位数是否合法即可。
tips:二月不用特殊处理,因为0229翻转过来的9220是闰年。
代码实现
#include <bits/stdc++.h>
using namespace std;
int day[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
int n, m, res = 0;
cin >> n >> m;
for (int M = 1; M <= 12; ++M) {
for (int d = 1; d <= day[M]; ++d) {
int y = (d % 10) * 1000 + (d / 10) * 100 + (M % 10) * 10 + M / 10;
int date = y * 10000 + M * 100 + d;
res += (date >= n && date <= m);
}
}
cout << res << '\n';
return 0;
}