给定一个32位的整数x 判断 仅用一个整型变量help实现 |使的help与x位数相同
|num%10的最低位–|num/10最高位–|
| |num%help/10同时去掉高低位 |
# include<iostream>
using namespace std;
bool isPalindrome() {
int x;
cout << "Please Input=X==" << endl;
cin >> x;
int help(1);
//首先将help变成与x相同位数
while (x / help >= 10) {
help *= 10;
}
while (x != 0) {
if (x % 10 != x / help) {
return false;
}
else {
x = (x%help) / 10;//去掉最低位和最高位
help = help / 100;
}
return true;
}
}
int main() {
bool flag = isPalindrome();
cout << flag << endl; //x=123321 //1
cout << boolalpha << flag << endl; //true
system("pause");
return 0;
}