我想在确认为回文之后查看这个词。但输出的结果与我的预期不同。请帮我配置我的代码中的错误
我希望实现的输出:
输入单词Madam
Word是古院:女士
#include <iostream>
#include <stack>
#include <string.h>
using namespace std;
int main ()
{
string words;
cout<<"Enter a word ";
cin>>words;
int wordSize = words.size();
stack<char> mystack;
for (int i=0; i<wordSize/2; ++i) {
mystack.push(tolower(words[0]));
words.erase(0,1);
}
if(words.size() > mystack.size()) {
words.erase(0, 1);
}
if(mystack.size() == 0) {
return true;
}
cout << "Popping out elements...";
while(!mystack.empty()) {
if(mystack.top() == words[0]) {
mystack.pop();
words.erase(0, 1);
if (mystack.size() == 0 || words.size() == 0) {
cout<<"Word is Palindrome: "<<<words<<endl;
return true;
}
}
else {
cout<<"Word is not Palindrome"<<endl;
return false;
}
}
}