Skip to content

Commit 41d98cd

Browse files
1 parent a3ce611 commit 41d98cd

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

PalindromeNumber.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class Solution {
2+
public:
3+
bool isPalindrome(int x) {
4+
if(x<0){
5+
return false;
6+
}
7+
string s="";
8+
while(x>0) {
9+
s.push_back(x%10);
10+
x /=10;
11+
}
12+
string rev=s;
13+
reverse(s.begin(),s.end());
14+
if(s.compare(rev) == 0) {
15+
return true;
16+
}
17+
return false;
18+
}
19+
};
20+
21+
int stringToInteger(string input) {
22+
return stoi(input);
23+
}
24+
25+
string boolToString(bool input) {
26+
return input ? "True" : "False";
27+
}
28+
29+
int main() {
30+
string line;
31+
while (getline(cin, line)) {
32+
int x = stringToInteger(line);
33+
34+
bool ret = Solution().isPalindrome(x);
35+
36+
string out = boolToString(ret);
37+
cout << out << endl;
38+
}
39+
return 0;
40+
}

0 commit comments

Comments
 (0)