Find the maximum number and find the maximum number
Maximum search time limit: 1000 MS | memory limit: 65535 KB difficulty: 2
-
Description
-
Delete m numbers in integer n so that the remaining numbers are the largest in the original order,
For example, when n = 92081346718538 and m = 10, the new maximum number is 9888.
-
Input
-
Enter a positive integer T in the first line, indicating that there are T groups of test data.
Each group of test data occupies one row, each row has two numbers n, m (n may be a large integer, but its number of digits does not exceed 100 bits, and ensure that the first data is not 0, m is less than the number of digits of the integer n)
-
Output
-
The output of each group of test data occupies one row, and the remaining number is the largest new number in the original order.
-
Sample Input
-
292081346718538 101008908 5
-
Sample output
-
988898
-
-
My code:
-
-
# Include <iostream> # include <cstring> using namespace std; int main () {int n, m, I, j, len, k; char a [110], B; cin> n; while (n --) {cin> a> m; len = strlen (a); k = 0;/* cout <"len: "<len <endl; */for (I = len-m-1; I> = 0; -- I) // specifies the total number of BITs {B = '0 '; for (j = k; a [j]! = '\ 0'; ++ j) // find the maximum number from a fixed number of digits {if (len-j-1> = I & (B-'0' <a [j]-'0 ')) // ensure that the number of digits after the number is obtained is greedy enough (because the number of digits is specified) {B = a [j]; k = j + 1 ;}} cout <B ;}cout <endl ;}return 0 ;}
Bidding Process:
-
-
#include <stdio.h>#include <string.h>int main(){ int k,l,max,z; char s[105],ans[105]; scanf("%d",&z); while(z--) { scanf("%s%d",s,&k); l = strlen(s); for(int i=0,q=-1;i<l-k;i++) { max = 0; for(int j=q+1;j<=k+i;j++) if(max < s[j]) max = s[j] , q = j; ans[i] = max; } ans[l-k] = '\0'; puts(ans); }return 0;}