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

hdu 1702 :ACboy needs your help again!(练习使用双端队列)

2013-04-05 21:31 369 查看
题目就是双端队列的基本操作

#include<iostream>
#include<stdio.h>
#include<deque>//双端队列头文件
#include<string.h>
using namespace std;
int main()
{
int n,m,x;
char s[5],s1[4],s2[4];
while(scanf("%d",&n)!=EOF)
{
while(n--)
{
deque<int>q;//双端队列的定义(并清空)
scanf("%d %s",&m,s);
while(m--)
{
scanf("%s",s1);
if(strcmp(s1,"IN")==0)
{
scanf("%d",&x);
q.push_back(x);
}
else if(!q.empty())
{
if(strcmp(s,"FIFO")==0)
{printf("%d\n",q.front());q.pop_front();}
else
{printf("%d\n",q.back());q.pop_back();}
}
else printf("None\n");
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: