72分求大佬帮助
查看原帖
72分求大佬帮助
606697
Phoebe_n楼主2022/1/20 15:52
#include<bits/stdc++.h>
using namespace std;
string n;
string shanchu(int x){
    string s;
    for(int i=0;i<n.size();i++){
        if(i==x)
            continue;
            else
         s+=n[i];
    }
    return s;
}
void check(string x){
     if(x[0]=='0'){
       x=shanchu(0);    
     }
}
int main(){
    int k;
    cin>>n;
    cin>>k;
    int cnt=0;
    int i=0;
    while(1){
    if(n[i]>n[i+1]){
        n=shanchu(i);
        check(n);
        i=0;
        cnt++;
        if(cnt==k)
        break;
    }
    else
    i++;
}
    for(int i=0;i<n.size();i++){
        cout<<n[i];
    }
    return 0;
    }

思路是一遍一遍的删除逆序的数 因为要输出数字所以删除了第一个0 谢谢大家❤

2022/1/20 15:52
加载中...