#include <bits/stdc++.h>
using namespace std;
int day1[13]={0,31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int day2[13]={0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isvalid(int year,int mounth,int day){
    if(year%400==0||(year%4==0&&year%100!=0)){
        if(mounth<=12&&mounth>=1){
            if(day>0&&day<=day1[mounth]) return true;
            else return false;
        }
        return false;
    }
    else{
        if(mounth<=12&&mounth>=1){
            if(day>0&&day<=day2[mounth]) return true;
            else return false;
        }
        return false;
    }
    return true;
}
int main() {
  int start,end;
  cin>>start>>end;
  int start_y=start/10000;
  int end_y=end/10000;
  int count=0;
  for(int i=start_y;i<=end_y;i++){
    string y=to_string(i);
    reverse(y.begin(),y.end());
    string m=y.substr(0,2);
    string d=y.substr(2,4);
    int day=stoi(d);
    int mounth=stoi(m);
    if(isvalid(i,mounth,day)){
        int valid_day=i*10000+mounth*100+day;
        if(valid_day>=start&&valid_day<=end) count++;
    }
  }
  cout<<count;
}
// 64 位输出请用 printf("%lld")

思路:可以枚举每一个日期然后判断是否是有效日期,但这样量太大,所以采用构造回文的方法,如何构造呢?可以发现每个回文日期是年份+年份倒置,所以我们就可以枚举每个年份然后构造,在判断是否为有效日期;

to_string()转成字符串;stoi()转成整形数字;reverse()逆转;substr()截取;

最后注意判断这个有效日期是不是在规定的日期范围内;