代码如下:#include <iostream>
using namespace std;
long int B(long int x)
{
long int m, b = 0;
while (x > 0)
{
m = x % 10;
x = x / 10;
b = b * 10 + m;
}
return b;
}
int main()
{
int x = 11, a[100], b[100], k, i, sum, q, w, l;
while (x > 10 )
{
sum = 0, i = 0, q = 0, w = 0;
k = x;
l = x;
while (l > 0)
{
b[q] = l % 8;
l = l / 8;
q++;
}
while (k > 0)
{
a[i] = k % 2;
k = k / 2;
i++;
}
for (int j = i - 1; j >= 0; j--)
{
sum = sum * 10 + a[j];
}
for (int j = q - 1; j >= 0; j--)
{
w = w* 10 + b[j];
}
if (sum == B(sum) && x == B(x)&&w==B(w))
{
cout << x;
break;
}
x = x + 2;
}
}
解释:1.专为n进制可以进行求余和递除的方式存到字符串,但是这是返向的(想象求一个数的倒数)
2.把这个字符串反着专为数字,判断其是否为回文数即可。