纯栈和队列应用的水题,这么好的水题我曾经怎么没发现
#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;
}