rt
P1165
代码:
#include<bits/stdc++.h>
using namespace std;
stack <int> st;
int main(){
int n;
cin>>n;
int c,x;
bool f=1;
while(n--){
cin>>c;
if(c==0){
cin>>x;
st.push(max(x,st.top()));
}
else if(c==1){
if(!st.empty())st.pop();
else f=0;
}
else if(c==2){
if(f==1)cout<<st.top()<<endl;
else cout<<0<<endl;
}
}
return 0;
}