1、熟练使用STL中的栈和队列。
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
int main() {
int T;
cin>>T;
for(int i=0; i<T; i++) {
int n;
cin>>n;
string s;
cin>>s;
if(s.compare("FILO")) {
queue<int> q;
for(int j=0; j<n; j++) {
string str;
cin>>str;
if(str.compare("IN")) {
if(q.size()>0) {
int ans = q.front();
q.pop();
cout<<ans<<endl;
} else {
cout<<"None"<<endl;
}
} else {
int tmp;
cin>>tmp;
q.push(tmp);
}
}
} else {
stack<int> st;
for(int j=0; j<n; j++) {
string str;
cin>>str;
if(str.compare("IN")) {
if(st.size()>0) {
int ans = st.top();
st.pop();
cout<<ans<<endl;
} else {
cout<<"None"<<endl;
}
} else {
int tmp;
cin>>tmp;
st.push(tmp);
}
}
}
}
return 0;
}