全RE求助(QAQ
查看原帖
全RE求助(QAQ
1177185
DRheEheAM_Gary楼主2024/7/23 11:40
#include<bits/stdc++.h>
using namespace std;
int n;
stack<int> q,qs;
void pushq(int ph){
    stack<int> uq;
    while(qs.top()>ph){
        uq.push(qs.top());
        qs.pop();
    }
    qs.push(ph);
    while(!uq.empty()){
        qs.push(uq.top());
        uq.pop();
    }
}
void delq(int dl){
    stack<int> uq;
    while(qs.top()>dl){
        uq.push(qs.top());
        qs.pop();
    }
    qs.pop();
    while(!uq.empty()){
        qs.push(uq.top());
        uq.pop();
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        int t;
        cin>>t;
        if(t==0){
            int x;
            cin>>x;
            q.push(x);
            pushq(x);
        }
        else if(t==1&&!q.empty()){
            delq(q.top());
            q.pop();
        }
        else if(t==2){
            if(qs.empty()) cout<<0<<endl;
            else cout<<qs.top()<<endl;
        }
    }
}

大佬们求调QAQ

2024/7/23 11:40
加载中...