以tt作为指针
先进后出
#include<algorithm>
#include<iostream>
using namespace std;
const int N=1e5+10;
int stk[N],tt;
void init()
{
tt=0;
}
void push(int x)
{
stk[++tt]=x;
}
int pop()
{
return stk[tt--];
}
bool empty()
{
return tt==0?true:false;
}
int query()
{
return stk[tt];
}
int main()
{
int m;
cin>>m;
init();
while(m--)
{
string s;
cin>>s;
if(s=="push")
{
int x;
cin>>x;
push(x);
}
else if(s=="query")
{
cout<<query()<<endl;
}
else if(s=="pop")
{
pop();
}
else
{
if(empty())
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
return 0;
}