#include using namespace std; int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool check(int d) { int year = d / 10000; int month = (d % 10000) / 100; int day = d % 100; // 求闰年 : 四年一闰,百年不闰,千年闰 if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) m[2] = 29; // 判断日,月是否符合 if (day > m[month]) return false; if (month > 12) return false; return true; } int main() { int date1, date2; cin >> date1 >> date2; int ans = 0; // 答案 // 枚举1000 ~ 9999的数字 , 因为这里是回文数,只要要枚举出来一半即可 for (int i = 1000; i <= 9999; i++) { // 将另一半算出来 int r = i; for (int j = i; j; j /= 10) r = r * 10 + j % 10; // 短除法求出位数,然后加上去 if (date1 <= r && r <= date2 && check(r)) ans++; } cout << ans << endl; return 0; }