Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
鍵盤輸入一個高精度的正整數n(≤100位),去掉其中任意s個數字後剩下的數字按照原來的左右次序組成一個新的正整數。編程對給定的n與s,尋找一種方案,使得剩下的數字組成的新數最小。
Input
輸入有多組 每組包括原始數n,要去掉的數字數s;
Output
輸出去掉s個數後最小的數
Sample Input
Sample Output
Hint
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main(){
char a[110];
int s,k;
while(~scanf("%s %d",&a,&s)){
k=strlen(a);
while(s){
for(int i=0;a[i];i++){
if(a[i]>a[i+1]){ //前一個比後一個大
strcpy(a+i,a+i+1); //把後面的複製到前面去
s--;
k--;
break;
}
}
}
while(a[0]=='0'&&k>1){ //去掉前面的零
strcpy(a,a+1);
k--;
}
printf("%s\n",a);
}
return 0;
}