Skip to content

Commit d95c68a

Browse files
committed
Added cpp code for Is Integer Palindrome without using Strings
1 parent 6c5b990 commit d95c68a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
bool solve(long int n)
5+
{
6+
long int orig_n = n;
7+
stack<long int>st;
8+
while(n > 0)
9+
{
10+
long int tmp = n%10;
11+
st.push(tmp);
12+
n = n/10;
13+
}
14+
n = orig_n;
15+
while(n > 0)
16+
{
17+
long int tmp = n%10;
18+
if(tmp != st.top())
19+
return false;
20+
21+
st.pop();
22+
n = n/10;
23+
}
24+
return true;
25+
}
26+
27+
int main()
28+
{
29+
long int n;
30+
cin>>n;
31+
32+
if(solve(n))
33+
cout<<"PALINDROME"<<endl;
34+
else
35+
cout<<"NOT A PALINDROME"<<endl;
36+
return 0;
37+
}

0 commit comments

Comments
 (0)