Question #55392

Write a program that reads a line of text, changes each uppercase letter to lowercase, and places each letter both in a queue and onto a stack. The program should then verify whether the line of text is a palindrome (a set of letters or numbers that is the same whether read forward or backward).

Expert's answer

#include <iostream>
#include <stdio.h>
#include <stack>
#include <queue>
using namespace std;

int main() {
stack<char> s;
queue<char> q;
int c;
while((c=getchar())!='\n') {
c=toupper(c);
s.push(c);
q.push(c);
}
char head;
char tail;
while(!s.empty()) {
head=q.front();
tail=s.top();
if(head!=tail) {
cout<<"Not palindrome\n";
return 0;
}
q.pop();
s.pop();
}
cout<<"Palindrome!\n";
return 0;
LATEST TUTORIALS
APPROVED BY CLIENTS