枚举年份就行了,很常见的一种统计日期的写法

#include <bits/stdc++.h>
#define il inline

using namespace std;
using ll = long long;
using ull = unsigned long long;
using int128=__int128_t;

const ll N = 2e5 + 5, mod =998244353, inf = 2e18;
const double esp=1e-9;
double PI=3.1415926;

int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

il void is_run(int y){
    if((y%4==0&&y%100!=0)||y%400==0)month[2]=29;
    else month[2]=28;
}

il void solve(){
    ll a,b;
    cin>>a>>b;
    int ans=0;
    for(int yera=0;yera<=9999;yera++){
        is_run(yera);
        string s=to_string(yera);
        int x=s[0]-'0',y=s[1]-'0',z=s[2]-'0',o=s[3]-'0';
        ll sum=yera*10000+o*1000+z*100+y*10+x;
        if(sum<a||sum>b)continue;
        ll day=y*10+x;
        ll mon=o*10+z;
        if(mon<=0||mon>12)continue;
        if(day<=0||day>31)continue;
        if(month[mon]>=day)ans++;
    }
    cout<<ans;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int t = 1;

    //cin >> t;
    
    while (t--) {

        solve();

    }

    return 0;
}