-
Notifications
You must be signed in to change notification settings - Fork 0
/
9.c
79 lines (71 loc) · 1.31 KB
/
9.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*#include <stdio.h>
int isPalindrome(int x);
int main (void)
{
int o;
scanf ("%d", &o);
printf ("%d\n", isPalindrome(o));
return 0;
}
int isPalindrome(int x)
{
int j = 0, p = x, i = 0;
if (x >= 10)
{
p = x;
while (p > 9)
{
p /= 10;
j ++;
}
printf ("%d\n", j);
int ar1[j + 1], ar2[j + 1];
i = j + 1;
for (p = 0; p < i; p ++, j --)
{
ar1[p] = x % 10;
ar2[j] = x % 10;
x /= 10;
printf ("%d\n", j);
}
while (j < i)
{
printf("%d", ar1[j]);
printf("%d\n", ar2[j]);
if (ar1[j] != ar2[j])
{
return 0;
}
j ++;
}
return 1;
}else if (x < 0)
{
return 0;
}else
{
return 1;
}
}
*/
#include <stdio.h>
int isPalindrome(int x);
int main(void) {
int o;
scanf("%d", &o);
printf("%d\n", isPalindrome(o));
return 0;
}
int isPalindrome(int x) {
if (x < 0) {
return 0; // 负数不是回文数
}
int reversed = 0;
int original = x;
while (x > 0) {
int digit = x % 10;
reversed = reversed * 10 + digit;
x /= 10;
}
return original == reversed;
}