这道题用STL怎么过不了
查看原帖
这道题用STL怎么过不了
374168
liswill楼主2021/9/3 17:44

RT,虽然过了,但是用 模拟栈 写的

#include<bits/stdc++.h>

using namespace std;
int max(int a,int b){return a>=b?a:b;}
int t1,t2,maxn=-1;
int main(){
    stack<int> s;
    int n;
    cin>>n;
    FOR(i,1,n){
        cin>>t1;
        if(t1==0){
            cin>>t2;
            maxn=max(maxn,t2);
            s.push(maxn);
        }
        if(t1==1){
            s.pop();
        }
        if(t1==2){
            if(s.empty()){
                cout<<0<<endl;
                continue;
            }
            cout<<s.top()<<endl;
        }
    }
    return 0;
}
2021/9/3 17:44
加载中...