Find the maximum number of time limits:MS | Memory limit:65535 KB Difficulty:2
-
Describe
-
Delete the M numbers in the integer n so that the remaining digits are the largest of the new numbers in the original order,
For example, when n=92081346718538,m=10, the new maximum number is 9888.
-
-
Input
-
-
the first line enters a positive integer t, which indicates that there is a T group of test data
One row for each set of test data, with two numbers per row n,m (n may be a large integer, but the number of bits does not exceed 100 bits, and the number of digits of the first non-0,m less than the integer n is guaranteed)
-
-
Output
-
-
the output of each set of test data is one row, the maximum new number of the output remaining number in the original order
-
-
Sample input
-
-
292081346718538 101008908 5
-
-
Sample output
-
-
988898
Test instructions: Finding the local maximum solution;
-
-
Code:
-
1#include <stdio.h>2#include <string.h>3 Charn[ the];4 voidFindintx) {5 intT=strlen (n), y,temp=0, I;6 CharMax;7y=t-x;8 while(y--) {max='0';9 for(i=temp;i<t-y;i++){Ten if(N[i]>max) max=n[i],temp=i+1; One } Aprintf"%c", max); - } - } the intMain () { - intt,m; -scanf"%d",&T); - while(t--){ +scanf"%s%d",n,&m); -Find (M);p UTS (""); + } A return 0; at}
Find the maximum number (greedy)