Describe
Given a decimal positive integer n (0 < n < 1000000000), the number on each digit is not 0. The number of bits for n is m.
Now remove the K-bit (0<k < m) from the M-bit to find out the minimum number of new integers generated?
For example: n = 9128456, k = 2, the new integer generated is a minimum of 12456
Enter the first line T, indicating that there is a T group of data;
Next T line, each row represents a set of test data, each set of test data contains two numbers n, K. Outputs the T-line, one number per line, representing the smallest integer that is obtained after the K-bit is removed from N. Sample input
29128456 21444 3
Sample output
124561
#include <stdio.h>#include<string.h>intMain () {Chara[Ten]; intb[Ten],len,i,t,k,j,p,q; scanf ("%d",&t); for(j=1; j<=t;j++) {memset (b,-1,sizeof(b)); scanf ("%s", a); scanf ("%d",&k); Len=strlen (a); for(i=1; i<=len;i++) B[i]=a[i-1]-'0'; for(p=1;p <=k;p++) for(i=1; i<=len;i++) { if(i==Len) {Len--; Break; } if(b[i]>b[i+1]) { for(q=i;q<len;q++) B[q]=b[q+1]; Len--; Break; } } for(i=1; i<=len;i++) if(b[i]>0) printf ("%d", B[i]); printf ("\ n"); }return 0;}
4.6 Greedy algorithm-3528: Minimum new integer