题目:
代码:
#include <iostream>
using namespace std;
const int N = 100010;
int st[N];
int top = -1;
int n;
int main()
{
cin >> n;
while(n--)
{
string s;
cin >> s;
//插入
if(s == "push")
{
int a;
cin >> a;
st[++top] = a;
}
//弹出
if(s == "pop")
{
top --;
}
//栈顶
if(s == "query")
{
cout << st[top] << endl;
}
//判断栈是否为空
if(s == "empty")
{
cout << (top == -1 ? "YES" : "NO") << endl;
}
}
}