基础练习 回文数 (蓝桥杯)

来源:互联网 发布:linux vi命令日志 编辑:程序博客网 时间:2024/05/17 02:43

#include <iostream>


using namespace std;
int f(int x)
{
int y,s=0;
y=x;
while(y>0)
{
s=s*10+y%10;     //x的最低位变成s的最高位
   y=y/10;           //去掉个位
}
if(s==x)
return 1;
else
return 0;
}






int main()
{


    for(int x=1000;x<=10000;x++){
            if(f(x))
            cout<<x<<endl;


    }
    return 0;
}