您的位置:首页 > 大数据 > 人工智能

hdu 1702 ACboy needs your help again!

2015-08-24 19:46 405 查看
纯栈和队列应用的水题,这么好的水题我以前怎么没发现

#include<iostream>
#include<queue>
#include<stack>
using namespace std;
int n;
void que()
{
queue<int>root;
for(int i=0;i<n;i++)
{
string cmd;
cin>>cmd;
if(cmd=="IN")
{
int x;
cin>>x;
root.push(x);
}
else
{
if(root.size())
{
cout<<root.front()<<endl;
root.pop();
}
else cout<<"None"<<endl;
}
}
}
void sta()
{
stack<int>root;
for(int i=0;i<n;i++)
{
string cmd;
cin>>cmd;
if(cmd=="IN")
{
int x;
cin>>x;
root.push(x);
}
else
{
if(root.size())
{
cout<<root.top()<<endl;
root.pop();
}
else cout<<"None"<<endl;
}
}
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n;
string cmd;
cin>>cmd;
if(cmd=="FIFO") que();
else sta();
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: