非常简短清晰的代码
C++ 代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, x;
int q[N], tt = -1, hh;
int main()
{
cin >> n;
while (n --)
{
string op;
cin >> op;
if (op == "push") cin >> q[ ++ tt];
else if (op == "pop") hh ++;
else if (op == "query")cout << q[hh] << "\n";
else if(hh <= tt) cout << "NO\n";
else cout << "YES\n";
}
return 0;
}