-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path*deque.cpp
More file actions
55 lines (44 loc) · 1.21 KB
/
Copy path*deque.cpp
File metadata and controls
55 lines (44 loc) · 1.21 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
#include <cctype>
#include <deque>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
bool is_palindrome(const std::string& s)
{
deque<char> d;
for (auto const &c : s) // filling deque
if (isalpha(c))
d.push_back(toupper(c));
char front, back;
while (d.size() > 1) // checking d is a palindrome
{
front = d.front();
back = d.back();
d.pop_front();
d.pop_back();
if (front != back)
return false;
}
return true;
}
int main()
{
cout << "Hi! This program checks a sentence or word on a palindrome." << endl
<< "It uses deque from STL. Enter 'exit' if you want to stop." << endl;
string str;
while (1 == 1) {
cout << "Enter the sentence or word: ";
cin >> str;
if (str == "Exit" or str == "exit")
break;
if (is_palindrome(str))
cout << "It is palindrome!" << endl;
else
cout << "It is not a palindrome :(" << endl;
}
cout << "\nThanks for using! Bye!" << endl;
system("pause");
return 0;
}