P11680 题解

· · 题解

题目传送门

思路

注意到 LR 范围都很小,于是遍历从 LR 找出所有的中尾相等数即可。

判断方法:先将数字 X 转为字符串 S(下标从 0 开始),其长度为 N,需满足:

AC CODE

#include<bits/stdc++.h>
using namespace std;
int read(){int x=0;char f=1,ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();return x*f;}
bool check(int x){
    string s=to_string(x);
    int n=s.size();
    if(!(n&1))
        return false;
    return s[0]==s[n-1]&&s[0]==s[n/2];
}
int main(){
    int T=read();
    while(T--){
        int l=read(),r=read();
        for(int i=l;i<=r;++i)
            if(check(i))
                printf("%d ",i);
        printf("\n");
    }
    return 0;
}