-
Notifications
You must be signed in to change notification settings - Fork 0
/
day-18-solution.py
49 lines (36 loc) · 1.03 KB
/
day-18-solution.py
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
class Solution:
def __init__(self):
self.stack = list()
self.queue = list()
# Method to push elements into the stack
def push_character(self, c):
self.stack.append(c)
# Method to pop out elements from the stack
def pop_character(self):
return self.stack.pop(-1)
# Method to enter element into the queue
def enqueue_character(self, c):
self.queue.append(c)
# Method to remove element from the queue
def dequeue_character(self):
return self.queue.pop(0)
if __name__ == "__main__":
# Read input string from stdin
s = input()
# Create the Solution class object
obj = Solution()
# Iterate over the string
for i, v in enumerate(s):
obj.push_character(v)
obj.enqueue_character(v)
# Set palindrome flag
is_palindrome = True
for i in range(len(s) // 2):
if obj.pop_character() != obj.dequeue_character():
is_palindrome = False
break
# Finally print whether string s is palindrome or not.
if is_palindrome:
print("The word, "+s+", is a palindrome.")
else:
print("The word, "+s+", is not a palindrome.")