-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.cpp
More file actions
70 lines (58 loc) · 1.25 KB
/
9.cpp
File metadata and controls
70 lines (58 loc) · 1.25 KB
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
#include<iostream>
using namespace std;
bool isPalindrome(int x)
{
int reverse = 0;
int initial = x;
//int flag = 0;
if (x < 0 || x > INT_MAX)
//cout << "Out of range" << endl;
return false;
//return 0;
//if (x < 0)
//x *= (-1);
//flag = 1;
//return false;
while (x)
{
reverse = reverse * 10 + x % 10;
x /= 10;
}
//if (flag == 1)
//reverse *= (-1);
//cout << "reverse is " << reverse << endl;
if (reverse < INT_MIN || reverse > INT_MAX)
//cout << "Out of range" << endl;
return false;
//cout << "initial is " << initial << endl;
//cout << "reverse is " << reverse << endl;
if (initial == reverse)
return true;
else
return false;
}
int main()
{
//cout << 12 / 10 << endl;
//cout << isPalindrome(-2147447412) << endl;
cout << isPalindrome(0) << endl;
//cout << isPalindrome(0) << endl;
//cout << isPalindrome(-12344321) << endl;
/*int n = -2147447412;
if (n < INT_MIN || n > INT_MAX)
//if (n < INT_MIN)
cout << "Out of range" << endl;
else
cout << "No problem" << endl;
int reverse = 0;
while (n)
{
reverse = reverse * 10 + n % 10;
n /= 10;
}
if (reverse < INT_MIN || reverse > INT_MAX)
cout << "Out of range" << endl;
else
cout << "No problem" << endl;
*/
}