My program currently finds a sentence level palindromes, and I want it to find w
ID: 3804777 • Letter: M
Question
My program currently finds a sentence level palindromes, and I want it to find word level palindromes. I want to run this program on each word in the string, as opposed to the whole string. If it doesn't fail on any of the words, then you have a word level palindrome. If it fails any of them, it's not a word level palindrome.
I need to write a program to tell if a word is a palindrome using stacks and queues. This needs to be able to only detect word level palindromes. It must ignore special charectors in the user input, and treat words as individual for palindrome. Some example would be
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please enter text to see if its a pallindrome?
user input : Able elba
Program: would say this is not a word level palindrome.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
An example where it would work:
Please enter text to see if its a pallindrome?
user input : Aba daad
Program would say this IS a word level palindrome. because its only looking at individual words to see if they are word level palindromes.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Another example of the program
User input: b5a1@14&ab f*89d4d(F
Program would say this IS a word level palindrome. because its only looking at individual words to see if they are word level palindromes and is also ignoring special symbols, numbers and case sensitivity of the letter input .
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. I do Not want sentance level palindromes to work, so something like "able was I ere I saw elba" should NOT work because it is a sentancee level palindrome thus should come back as Not a palindrome. Here is the code I have so far. If you could explain the changes you make so I can learn, I would upvote and be very thankful. Thanks for any help.
include // Provides assert
include // Provides isalpha, toupper
include // Provides cout, cin, peek
include // Provides the queue template class
include // Provides the stack template class
using namespace std;
int main() {
}
Explanation / Answer
Answer:
#include <stdio.h>
#include <string.h>
void push(char);
char pop();
char input[100];
int up = -1;
void main()
{
char str[100];
int i, inc = 0, len;
printf("Enter string to check it is palindrome or not : ");
scanf("%s", str);
len = strlen(str);
for (i = 0; i < len; i++)
{
push(str[i]);
}
for (i = 0; i < len; i++)
{
if (str[i] == pop())
inc++;
}
if (inc == len)
printf("%s is a Palindrome string ", str);
else
printf("%s is not a palindrome string ", str);
}
void push(char c)
{
input[++up] = c;
}
char pop()
{
return(input[up--]);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.