Find the maximum number of time limits: +Ms | Memory Limit:65535KB 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
-
-
Source
-
The
-
sixth session of Itat semi-finals B Vol. 2 adaptation
-
-
Uploaded by
Acm_ Zhao Minhao
Idea: If the maximum number, the number of m+1~len-1 need to be retained first, so that end=m,
Find the largest number from the 0~end. Write down the subscript t, output the maximum number, end++,
Then find the maximum number, output, and so on from the T+1~end, and the maximum!
#include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;char s[102];int main () {int i,j,m,t,k,len,test,end,ans;scanf ("%d", &test), while (test--) {scanf ("%s%d", s,&m); Len=strlen (s); end=m; T=0;for (i=0,k=0;i<=end;) { ans=s[i];for (j=i+1;j<=end;j++) { if (S[j]>ans) { ans=s[j ]; t=j;} } end++;k++;i=t+1;printf ("%c", S[t]), T++;if (k==len-m)//t control the number of bits of output, the end of the flag. Break ;} printf ("\ n");} return 0;}
Find maximum number (nyoj448) (greedy)