word level palindrome program with stacks and queues I have a good portion of my
ID: 3804275 • Letter: W
Question
word level palindrome program with stacks and queues
I have a good portion of my program finished, I am just trying to figure out how to do some final things to it. I want the program to only check for letters a through z and A = Z, treating uppercase and lower case as the same thing. I want it to ignore any other characters and to just realize word level palindromes, not sentence level, so for example a%345b@a c24&c8d)9cc would be a word level palindrome since the program would ignore the numbers and special characters and only look at each word or set of letters as a candidate. Since uppercase and lowercase will be treated the same, something like AbBa baB should also come back as a word level palindrome. Here is the code I have so far. Thanks for any help.
include <cassert> // Provides assert
include <cctype> // Provides isalpha, toupper
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() {
}
Explanation / Answer
Answer:
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main (void)
{
queue <char> value;
string input;
int length;
cout<<"Please enter a series of characters."<<endl;
getline (cin, input);
bool isPalindrome = false;
if (inputs.size() > 0)
{
int length = input.size() / 2;
for (int i=0; i<length; i++)
{
value.push(inputs[i]);
}
isPalindrome = true;
for (int i = 1; i <= length && isPalindrome; ++i)
{
isPalindrome = value.front() == inputs[inputs.size() - i];
value.pop();
}
}
if(!isPalindrome)
{
cout<<"Is not a palindrome."<<endl;
}
else
{
cout<<"Is a palindrome."<<endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.