4.6 Greedy algorithm-3528: Minimum new integer

Source: Internet
Author: User

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

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.