#include "stdafx.h"
#include<string>
#include<iostream>
#include<stack>
#include<queue>
using namespace std;
int main()
{
/*---------定义栈和队列------------*/
stack<char> s;
queue<char> q;
/*-----字符串进栈和队列------------*/
char c;
while(cin>>c&&c!='@')
{
s.push(c);
q.push(c);
cout<<s.top()<<" "<<q.back()<<endl;
}
cout<<s.size()<<endl;
/*-----字符出栈出队列------------*/
while(s.empty()==0)
{
if(s.top()==q.front())
{
cout<<s.top()<<" "<<q.front()<<endl;
s.pop();
q.pop();
}
else
break;
}
if(s.empty()==true)
cout<<"此字符串是回文"<<endl;
else
cout<<"此字符串不是回文"<<endl;
return 0;
}
C++回文的实现代码
最新推荐文章于 2024-03-20 21:27:20 发布