#include<iostream>

using namespace std;
#define maxsize 100
typedef int elemtype;
typedef struct node {
elemtype elem[maxsize];
int top;
}sestack;
bool create(node& S) {
S.top = -1;
return 1;
}
bool isempty(node& S) {
if (S.top = -1) {
cout << "栈为空" << endl;
return 1;
}
return 0;
}
bool isfull(node& S) {
if (S.top + 1 == maxsize) {
cout << "栈满" << endl;
return 1;
}
return 0;
}
int enstack(node& S,int e) {
if (isfull(S) == 1)return 0;
S.elem[S.top+1] = e;
S.top++;
return 1;
}
int destack(node& S,int e) {
if (isempty(S)==1)return 0;
e=S.elem[S.top+1];
S.top--;
return e;
}
bool huiwen(node& S) {
node P;
create(P);
elemtype e=0;
int i = S.top + 1, n = 0, m = 0;
while (i != 0) {
e=destack(S, e);
if (e != '#') {
P.elem[P.top + 1] = S.elem[i];
P.top++;
}
else
n++;
if (n != 1) {
for (int i = 0; i < P.top + 1; i++) {
cout << P.elem[i];
}
m = (P.top + 1) / 2;
for (int i = 0; i < (P.top + 1) / 2; i++) {
if (P.elem[i] == P.elem[P.top])m--;
}
if (m == 0)cout << "是回文" << endl;
else cout << "不是回文" << endl;
n--;
}
i--;
}
return 1;
}
int main() {
node S;
create(S); // S.top = -1;
int num = 0;
elemtype e;
cout << "输入需要判断回文的字符串的个数:" << endl;
cin >> num;
num += 1; //
cout << "输入的每个字符串以#相隔,格式如下:" << endl;
cout << "#asffs#ffsff#dhuse#" << endl;
cout << "请输入字符串:" << endl;
while (num!=0) {
cin >> e;
if (e == '#') {
num--;
}
enstack(S, e);
}
huiwen(S);
return 0;
}


为什么输入的值没有缓存到e中,导致无法触发n--从而跳出while循环