C++ 代码
#include <iostream>
using namespace std;
const int N = 1e5 + 10;
int e[N], head = 0, idx = 0;
string s;
int m, x;
void empty()
{
if(idx == head) cout << "YES" << endl;
else cout << "NO" << endl;
}
void query()
{
cout << e[head] << endl;
}
int main()
{
cin >> m;
while (m -- )
{
cin >> s;
if(s == "push")
{
cin >> x;
e[idx ++] = x;
}
else if(s == "pop") head ++;
else if(s == "empty") empty();
else query();
}
return 0;
}