Ljh421 @ 2024-07-03 09:07:22
#include<bits/stdc++.h>
//保留小数 fixed << setprecision(3)
using namespace std;
int st,ok,sum;
int dm[20]={0,31,0,31,30,31,30,31,31,30,31,30,31};
bool hw(int xxx){
int x[10],a=1;
for(int i=1;i<=8;i++){
x[i]=xxx/a%10;
a*=10;
}
for(int i=1;i<=4;i++){
if(x[i]!=x[9-i]){
return false;
}
}
return true;
}
int main(){
cin>>st>>ok;
if(hw(st)){
sum++;
//cout<<st<<endl;
}
while(st<ok){
st++;
int day=st%100,month=st/100%100,year=st/10000;
if(month==2){
if((year%4==0&&year&100!=0)||year%400==0){
dm[2]=29;
}else{
dm[2]=28;
}
}
if(day>dm[month]){
st=st+101-day;
month++;
}
if(month>12){
st=st+8800;
year++;
}
if(hw(st)){
sum++;
//cout<<st<<endl;
}
}
cout<<sum;
return 0;
}
by sunrunjie @ 2024-07-06 17:33:20
@Ljh421
#include<bits/stdc++.h>
using namespace std;
int a[30]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
int x,y,ans=0;
cin>>x>>y;
for(int i=1;i<=12;i++){
for(int j=1;j<=a[i];j++){
int g,s,b,q;
g=j%10;
s=j/10;
b=i%10;
q=i/10;
int sum=g+s*10+b*100+q*1000+q*10000+b*100000+s*1000000+g*10000000;
if(sum>=x&&sum<=y){
ans++;
}
}
}
cout<<ans;
}
求关注