-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path23 Stack String Palindrome.cpp
More file actions
69 lines (54 loc) · 1.23 KB
/
23 Stack String Palindrome.cpp
File metadata and controls
69 lines (54 loc) · 1.23 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
/*
Krishna has shown one magic to reverse the given string. He asked his friend that can you write a code to check the given string is palindrome or not.
Sample 1: Line 1: Enter the string : amma Line 2: Palindrome
Sample 1: Line 1 : Enter the expression : papa Line 2 : Not Palindrome
Input Format
User should pass the input in formate of string
Constraints
String expression length should > 0
Output Format
The result will display as Palindrome or Not Palindrome.
Sample Input 0
malayalam
Sample Output 0
Palindrome
Explanation 0
Line 1 : Enter the expression : malayalam Line 2 : Palindrome
*/
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
char *stack=NULL;
int n,top=-1;
void push(char x)
{
stack[++top]=x;
}
void pop()
{
if(top!=-1)
top--;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
string s;
cin>>s;
n = s.length();
stack = new char[n];
for(int i=0;i<n;i++)
push(s[i]);
for(int i=0;i<n;i++)
{
if(s[i]!=stack[top])
{
cout<<"Not Palindrome";
exit(0);
}
pop();
}
cout<<"Palindrome";
return 0;
}