#include <iostream>
#include <stack>
#include <cctype>
using namespace std;
// Function to print original string followed by reversed string using a stack
void printOriginalAndReversed(const string& input) {
stack<char> charStack;
// Push characters onto the stack
for (char ch : input) {
charStack.push(ch);
// Print original string
cout << "Original String: " << input << endl;
// Print reversed string
cout << "Reversed String: ";
while (!charStack.empty()) {
cout << charStack.top();
charStack.pop();
cout << endl;
}
// Function to check whether a given string is a palindrome or not
bool isPalindrome(const string& input) {
stack<char> charStack;
// Push characters onto the stack
for (char ch : input) {
charStack.push(ch);
// Compare characters from the stack with the original string
for (char ch : input) {
if (charStack.top() != ch) {
return false;
charStack.pop();
return true;
int main() {
string input;
// Input from the user
cout << "Enter a string: ";
getline(cin, input);
// Remove punctuation, convert to lowercase, and remove spaces
string cleanInput;
for (char ch : input) {
if (isalnum(ch)) {
cleanInput += tolower(ch);
// a) Print original string followed by reversed string using a stack
printOriginalAndReversed(cleanInput);
// b) Check whether the given string is a palindrome or not
if (isPalindrome(cleanInput)) {
cout << "The string is a palindrome." << endl;
} else {
cout << "The string is not a palindrome." << endl;
return 0;