其实就是回文数,将数字拆分一下,然后首和尾比较就可以了。我这里用的是数学上取模进行拆分的,刚刚看题解有大佬用的to_string 函数挺妙的。代码量比这个简洁
#include<iostream>
using namespace std;
const int N=4;
bool check(int x) {
int a[N],i=0;
while(x) { //将
a[i++]=x%10;
x/=10;
}
int len=i;
for(int i=0;i<len/2;i++) {
if(a[i]!=a[len-i-1]) return false;
}
return true;
}
int main() {
for(int i=0;i<=256;i++) {
if(check(i*i)) {
printf("%d\n",i);
}
}
}