Find the maximum number and find the maximum number

Source: Internet
Author: User

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;}        


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.