编辑代码

#include<iostream>
using namespace std;
int stack[1000000],top;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string op;
		cin>>op;
		if(op=="push"){
			int x;
			cin>>x;
			stack[++top]=x;
		}
		if(op=="pop")
			top--;
		if(op=="empty"){
			if(top==0){
				cout<<"YES"<<endl;
			}
			else{
				cout<<"NO"<<endl;
			}
		}
		if(op=="query"){
			cout<<stack[top]<<endl;
		}
	}
	return 0;
}