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

HDU 1702 ACboy needs your help again!

2014-04-16 15:02 405 查看
题解:栈和队列的基本运用,熟练一下STL。

#include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,m;
string str;
cin>>n>>str;
if(str=="FIFO"){
queue q;
while(n--){
cin>>str;
if(str=="IN")cin>>m,q.push(m);
else{
if(q.empty())puts("None");
else printf("%d\n",q.front()),q.pop();
}
}
if(!q.empty())q.pop();
}
else{
stack s;
while(n--){
cin>>str;
if(str=="IN")cin>>m,s.push(m);
else{
if(s.empty())puts("None");
else printf("%d\n",s.top()),s.pop();
}
}
if(!s.empty())s.pop();
}
}
return 0 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: