删数问题求助
  • 板块题目总版
  • 楼主Coco_Condy
  • 当前回复1
  • 已保存回复1
  • 发布时间2021/10/3 21:42
  • 上次更新2023/11/4 04:59:09
查看原帖
删数问题求助
377797
Coco_Condy楼主2021/10/3 21:42

P1106RE求救 代码如下:

#include<bits/stdc++.h>
using namespace std;
int n,m;
string s;
stack<int> q,w;
int main(){
    ios::sync_with_stdio(false);
    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:42
加载中...