-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalindrome.cpp
41 lines (34 loc) · 874 Bytes
/
palindrome.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
#include <ostream>
#include <deque>
using namespace std;
bool IsPalindrome(string word)
{
deque<char> wordDeque;
for(char c : word)
if (isalpha(c))
wordDeque.push_back(tolower(c));
while (wordDeque.size() > 1)
{
if (wordDeque.front() != wordDeque.back())
return false;
wordDeque.pop_front();
wordDeque.pop_back();
}
return true;
}
void PalindromeTest(string word)
{
if (IsPalindrome(word))
cout << "'" << word << "' is a palindrome" << endl;
else
cout << "'" << word << "' is not a palindrome" << endl;
}
void TestPalindromes()
{
PalindromeTest("Step on no pets");
PalindromeTest("Mars is great");
PalindromeTest("Eva, can I see bees in a cave?");
PalindromeTest("aba");
PalindromeTest("F");
PalindromeTest("abbaa");
}