PTA (BasicLevel) -1023 set a minimum number

First, define the problem

0-9 each given a number. You can arrange these numbers in any order, but must be fully utilized. The goal is to make the resulting number as small as possible (do not pay attention to the first 0).

For example: Given two 0, 1 two, three 5, a 8, we get the minimum number is 10015558. The minimum number is now given a number, please write program output can be composed of.

 

Input formats:

Input 10 is given a non-negative integer in a row, we have the sequence represents the number 0, the number of number 1, number 9 ....... Separated by a space between integer. The total number of 10 digits is no more than 50, and has at least one non-zero digit.

Output formats:

The smallest number in a row can be output thereof.

Sample input:

2 2 0 0 0 3 0 0 1 0

Sample output:

10015558
 

Second, problem-solving

nums = [int(bi) for bi in str(input()).split(" ")]

# First, find the smallest non-zero number, the most significant bits 
min = 0
 for I in Range (. 1, 10 ):
     IF the nums [I] =! 0:
        min = in
        nums[i] -= 1
        break

Number = min    
 # The remaining small to large number of splicing 
DEF concat_by_mult (Number, the nums):
     for I in Range (10 ):
         IF the nums [I] =! 0:
             for J in Range (the nums [I]):
                number = number * 10 + i
    return number

def concat_char(number, nums):
    number = str(number)
    for i in range(10):
        if nums[i] != 0:
            for j in range(nums[i]):
                number = number + str(i)
    return number    
    
print(concat_char(number, nums))

 

Guess you like

Origin www.cnblogs.com/justLittleStar/p/11729527.html