板子如下
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int n,Stack[N],tt,x;//tt是top
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
tt=0;
cin>>n;
while(n--){
string op;
cin>>op;
if(op=="push"){//压人x
cin>>x; Stack[++tt]=x;
}else if(op=="pop"){
--tt;
}else if(op=="empty"){//是否为空
if(tt==0) cout<<"YES\n";
else cout<<"NO\n";
}else cout<<Stack[tt]<<endl;//取top值
}
return 0;
} 
京公网安备 11010502036488号