forked from rahulsain/Hackerrank_30daysOFcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChidu2000.cpp
63 lines (51 loc) · 1.28 KB
/
Chidu2000.cpp
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
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
class Solution {
public:
void pushCharacter(const char c_) { _s.push(c_); }
void enqueueCharacter(const char c_) { _q.push(c_); }
char popCharacter() {
char c = _s.top();
_s.pop();
return c;
}
char dequeueCharacter() {
char c = _q.front();
_q.pop();
return c;
}
private:
queue<char> _q;
stack<char> _s;
};
int main() {
// reading the string without using getline function
char c,last=0;
string s;
while(cin.get(c)){ // read one character at a time
if(last && (isalpha(last) || (isalpha(last) && isalpha(c))))
s.push_back(last);
last=c;
}
Solution obj;
for (int i = 0; i < s.length(); i++) {
obj.pushCharacter(s[i]);
obj.enqueueCharacter(s[i]);
}
bool isPalindrome = true;
for (int i = 0; i < s.length() / 2; i++) {
if (obj.popCharacter() != obj.dequeueCharacter()) {
isPalindrome = false;
break;
}
}
if (isPalindrome) {
cout << "The word, " << s << ", is a palindrome.";
} else {
cout << "The word, " << s << ", is not a palindrome.";
}
return 0;
}