题目就是双端队列的基本操作
#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; }