#include <iostream>
#include <vector>
using namespace std;
const int N = 100010;
vector<int> stack;
int main()
{
int m;
cin>>m;
while(m--)
{
string s;
cin>>s;
if(s == "push")
{
int x;
cin>>x;
stack.push_back(x);
}
if(s == "pop")
{
stack.pop_back();
}
if(s == "empty")
{
if(stack.empty()) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
if(s == "query")
{
cout<<stack.back()<<endl;
}
}
return 0;
}
判断empty的时候,还可以通过判断stack.size()是否为0来判断栈是否为空。