题解 | #回文对称数#
回文对称数
https://www.nowcoder.com/practice/5b143af8328f4e42adf5e10397ae44ef
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int i = 1;
while (i <= n)
{
int temp_rev = 0;
int temp = i;
while (temp > temp_rev)
{
temp_rev = temp_rev * 10 + temp % 10;
temp /= 10;
}
if ((temp_rev == temp || temp_rev / 10 == temp) && (i % 10 != 0))
cout << i << endl;
i++;
}
}
// 64 位输出请用 printf("%lld")
回文数的写法,判断条件加上末位不是0。
C++题解 文章被收录于专栏
记录在牛客网用C++刷题的题解思路


查看15道真题和解析