求助
查看原帖
求助
377797
Coco_Condy楼主2021/10/3 21:02
#include<bits/stdc++.h>
using namespace std;
int n,m;
string s;
stack<int> q,w;
int main(){
    cin>>s;
    cin>>m;
    n=s.length();
    n-=m;
    for(int i=0;i<s.length();i++){
        int x=s[i]-'0';
        if(q.empty()||m==0){
            q.push(x);
        }else if(x<q.top()){
            while(x<q.top()&&m&&!q.empty()){
                m--;
                q.pop();
            }
            q.push(x);
        }else{
            q.push(x);
        }
    }
    while(!q.empty()){
        w.push(q.top());
        q.pop();
    }
    while(n&&!w.empty()){
        cout<<w.top();
        w.pop();
        n--;
    }
    return 0;
}
2021/10/3 21:02
加载中...