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

HDU 1702 ACboy needs your help again!

2012-07-27 14:05 405 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1702

G++交,基本stl栈和队列操作

View Code

#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 <int> 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 <int> 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 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: