C++ 代码
#include <iostream>
using namespace std;
const int N = 100010;
int q[N],tail;
int main(){
int n;
cin >> n;
while(n--){
string op;
int x;
cin >> op ;
if(op == "push"){
cin >> x;
q[++tail] = x;
}else if(op == "pop"){
--tail;
}else if(op == "query"){
cout << q[tail] <<endl;
}else{
if (tail == 0) cout << "YES" <<endl;
else cout << "NO" <<endl;
}
}
return 0;
}