# include<iostream>
# include<stack>
# include<string>
# include<queue>
using namespace std;
int main() { //判断是不是回文串
stack<char> s;
queue<char> q;
char a;
cout << "Begin Input---" << endl;
cin >> a;
while (a != '#') {
s.push(a);
q.push(a);
cin >> a;
}
while (!q.empty()) {
if (q.front() == s.top()) {
q.pop();
s.pop();
}
else {
cout << "不是回文串!!" << endl;
break;
}
if (s.empty()) {
cout << "是回文串!!" << endl;
}
}
system("pause");
}
4.如何使用栈和队列实现回文串
最新推荐文章于 2021-10-09 21:51:01 发布