#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int stk[N], tt;
int main()
{
int m;
cin >> m;
string op;
int x;
while (m -- )
{
cin >> op;
if (op == "push")
{
cin >> x;
stk[++ tt] = x;
}
if (op == "pop")
{
tt --;
}
if (op == "empty")
{
cout << (!tt ? "YES" : "NO") << endl;
}
if (op == "query")
{
cout << stk[tt] << endl;
}
}
}
算法基础课:模拟栈
最新推荐文章于 2024-08-08 15:12:59 发布