1 #include<iostream> 2 using namespace std; 3 const int N=1e5+10; 4 int m,idx; 5 int stk[N]; 6 int main (void){ 7 cin>>m; 8 for(int i=0;i<m;i++){ 9 string op; 10 int x; 11 cin>>op; 12 if(op=="push"){ 13 cin>>x; 14 stk[++idx]=x; 15 }else if(op=="pop"){ 16 if(idx>0) 17 idx--; 18 else{ 19 ; 20 } 21 }else if(op=="empty"){ 22 if(idx==0){ 23 cout<<"YES"<<endl; 24 }else{ 25 cout<<"NO"<<endl;; 26 } 27 }else if(op=="query"){ 28 cout<<stk[idx]<<endl; 29 } 30 } 31 return 0; 32 }