为什么感觉代码中没有考虑到最高位、中间位和个位是9但不全为9(例如90909)的情况,但答案还是对的?
照代码来看不应该变成了00000有错误了吗
#include <stdio.h>
#include <math.h>
int is_palindrome(int x)
{
if (x < 0 || (x % 10 == 0 && x != 0))
return 0;
int reverted = 0;
while (x > reverted)
{
reverted = reverted * 10 + x % 10;
x /= 10;
}
return x == reverted || x == reverted / 10;
}
int main()
{
int n;
scanf("%d", &n);
while (1)
{
n++;
if (is_palindrome(n))
{
printf("%d", n);
break;
}
}
return 0;
}