思路很明确具体解释我就不写了看代码吧
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int ans=0;
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int check(int x)
{
int year = x / 10000,month = x / 100 % 100,day = x % 100;
if(month <= 0||month > 12||day <= 0) return 0; //别忘了day=0的情况
if(day > days[month]&&month != 2) return 0;//一定不能少month!=2不然会在这一步直接返回不执行之后的
if(month == 2)
{
int k;
k = year % 4 ==0&&year % 100||year % 400 == 0;
if(day > days[month] + k) return 0;
}
return 1;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i = 1000;i <10000;i ++)
{
int a = i,b = i;
for(int j = 0;j < 4;j ++)
{
a = a * 10 + b % 10;
b/=10;
}
if(a >= n&&a <= m&&check(a)) ans++;
}
cout<<ans<<endl;;
return 0;
}