水啊水~水啊水~~~~
AC代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
int main(){
int T, N;
char s[10];
cin >> T;
while( T-- ){
cin >> N >> s;
if( strcmp( s, "FIFO" ) == 0 ){
queue<int> q;
for( int i = 0; i < N; i++ ){
cin >> s;
if( strcmp( s, "IN" ) == 0 ){
int temp;
cin >> temp;
q.push( temp );
}else{
if( !q.empty() ){
cout << q.front() << endl;
q.pop();
}else{
cout << "None" << endl;
}
}
}
}else{
stack<int> q;
for( int i = 0; i < N; i++ ){
cin >> s;
if( strcmp( s, "IN" ) == 0 ){
int temp;
cin >> temp;
q.push( temp );
}else{
if( !q.empty() ){
cout << q.top() << endl;
q.pop();
}else{
cout << "None" << endl;
}
}
}
}
}
return 0;
}