题解 | #回文对称数#
回文对称数
https://ac.nowcoder.com/acm/problem/22169
拆数列,倒序判断
比如761 拆成7 6 1倒序167≠761,就返回167 == 761;也就是一个bool值代表是否为回文数。
#include<iostream>
using namespace std;
bool isPa(int num) {
int t = num;
int rnum = 0;
while (t != 0) {
int remainder = t % 10;//拆
rnum = rnum * 10 + remainder;//***队
t /= 10;//拆分数
}
return num == rnum;//是否倒序后为回文结果,bool值
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
if (isPa(i)) {//屎回文就输出
cout << i << endl;
}
}
return 0;
}