C++回文数

//输入一个数,输出那个数以内的回文数
#include<bits/stdc++.h>
using namespace std;
int m(int x)
{
    int s=0,d=1;
    do
    {   d*=10;
        s++;
    }while(d<=x);
    return s;
}
int main()
{
    int a;
    cin>>a;
    cout<<"1";
    for(int i=2;i<=a;i++)
    {
        int dt=m(i),g[dt+1],h=i;
        bool e=1;
        for(int j=1;j<=dt;j++)
        {
            g[j]=h%10;
            h/=10;
        }
        for(int k=1;k<=(dt+1)/2;k++)
            e=(g[k]==g[dt+1-k])?e:0;
        if(e) cout<<endl<<i;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/csdn_3011692917/article/details/79680246
今日推荐