洛谷P1106 删数问题

如下。这可能是思路比较清晰的代码了。

为了各位阅读方便,我将变量名加长了。

谢谢阅读233

#include<bits/stdc++.h>
using namespace std;
char ints[250];

int main()
{
int n;
cin>>ints>>n;
int length;length = strlen(ints);
static int currents[100];
int currentCheckingDigit=1;
int ptr=0;
while (currentCheckingDigit<=length){
if (n!=0){
int min =10000;int rminat=0;//relative min at(numbers needed to be off)
for (int i=ptr;i<=ptr+n;i++){
if (ints[i]-'0'<min) {min=ints[i]-'0';rminat=i-ptr;}//find out the minium and where it is
}
for (int i=ptr;i<=ptr+rminat-1;i++){
ints[i]='X';//everything before ptr+rminat will be elimated
}

n-=rminat;
ptr+=rminat+1;
currentCheckingDigit++;
}
else{
currentCheckingDigit++;
}
}
for (int i=0;i<=length-1;i++){
if (ints[i]=='0'||ints[i]=='X') ints[i]='X';
if (ints[i]!='0'&&ints[i]!='X') break;
}
for (int i=0;i<=length-1;i++) if (ints[i]!='X')cout<<ints[i];
system("pause");
return 0;
}
posted @ 2017-08-03 15:16  pityhero  阅读(143)  评论(0编辑  收藏  举报