题目连接:ACboy needs your help again!
解题思路:直接模拟就好了。用STL。
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
using namespace std;
int n, t, num;
int tem;
char s[20];
queue<int> mq;
stack<int> ms;
int main(){
int i, j, k;
//freopen("1.out", "w", stdout);
while(~scanf("%d", &t)){
for(int T = 0; T < t; T++){
scanf("%d%s", &n, &s);
if(!strcmp(s, "FIFO")){
while(!mq.empty())mq.pop();
for(i = 0; i < n; i++){
scanf("%s", &s);
if(s[0] == 'I'){
scanf("%d", &tem);
mq.push(tem);
}
else{
if(mq.size() == 0){
puts("None");
}
else{
printf("%d\n", mq.front());
mq.pop();
}
}
}
}
if(!strcmp(s, "FILO")){
while(!ms.empty())ms.pop();
for(i = 0; i < n; i++){
scanf("%s", &s);
if(s[0] == 'I'){
scanf("%d", &tem);
ms.push(tem);
}
else{
if(ms.size() == 0){
puts("None");
}
else{
printf("%d\n", ms.top());
ms.pop();
}
}
}
}
}
}
return 0;
}