利用栈和队列的特性设计一个算法,用于判断一个字符串是否为回文。
#include<iostream>
#include<stack>
#include<queue>
using namespace std;
int main()
{
stack<char> s;
queue<char> t;
char c;
int i=0;
while((c=getchar())!='\n')
{
s.push(c);
t.push(c);
i++;
}
while(i--)
{
if(s.top()==t.front())
{s.pop(); t.pop(); }
else { cout<<"不";break;}
}
cout<<"是回文"<<endl;
return 0;
}