C++ 代码
#include <cstdio>
#include <iostream>
using namespace std;
const int M = 100010;
int q[M];
int m;
int main()
{
cin >> m;
int hh = 0, tt = -1;
while (m -- )
{
string op;
cin >> op;
if (op == "push") scanf("%d", &q[++ tt]);
else if (op == "pop") q[hh ++ ];
else if (op == "empty")
{
string pp;
if (hh <= tt) printf("NO\n");
else printf("YES\n");
}
else printf("%d\n", q[hh]);
}
return 0;
}