// https://www.luogu.com.cn/problem/P2010 #include using namespace std; //月份日期常数数组 int months[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //判断是不是闰年 bool LeapYear(int year) { return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0); } //是不是回文字符串 bool isHW(string s) { string t = s; reverse(t.begin(), t.end()); return s == t; } int cnt; int main() { int st, ed; cin >> st >> ed; int y1 = st / 10000; int y2 = ed / 10000; //枚举年份 for (int i = y1; i <= y2; i++) // 枚举月份 for (int j = 1; j <= 12; j++) { //枚举日期 int day = months[j]; if (LeapYear(i) && j == 2) day = 29; //闰年二月份,共29天 for (int k = 1; k <= day; k++) { int s = i * 10000 + j * 100 + k; //与范围字符串st,ed进行比较,如果不在范围内,continue if (s < st || s > ed) continue; //日期字符串符合字典序 //判断是不是回文 char x[10]; sprintf(x, "%d", s); if (isHW(x)) cnt++; } } //输出 printf("%d\n", cnt); return 0; }