single word palindrome
i want to change this code and make it check for single word palindromes. ex: hanah jenjen unoiunoi
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 <cassert> // Provides assert
#include <cctype> // Provides isalpha, toupper
#include <cstdlib> // Provides EXIT_SUCCESS
#include <iostream> // Provides cout, cin, peek
#include <queue> // Provides the queue template class
#include <stack> // Provides the stack template class
using namespace std;
int main( )
{
queue<char> q;
stack<char> s;
char letter;
queue<char>::size_type mismatches = 0;
cout << "Enter a line and I will see if it's a palindrome:" << endl;
while (cin.peek( ) != '\n')
{
cin >> letter;
if (isalpha(letter))
{
q.push(toupper(letter));
s.push(toupper(letter));
}
}
while ((!q.empty( )) && (!s.empty( )))
{
if (q.front( ) != s.top( ))
++mismatches;
q.pop( );
s.pop( );
}
if (mismatches == 0)
cout << "That is a palindrome." << endl;
else
cout << "That is not a palindrome." << endl;
return EXIT_SUCCESS;
}
|
Topic archived. No new replies allowed.