题目描述
给定数字0-9各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意0不能做首位)。例如: 给定两个0,两个1,三个5,一个8,我们得到的最小的数就是10015558。 现给定数字,请编写程序输出能够组成的最小的数。
输入描述:
每个输入包含1个测试用例。每个测试用例在一行中给出10个非负整数,顺序表示我们拥有数字0、数字1、……数字9的个数。整数间用一个空 格分隔。10个数字的总个数不超过50,且至少拥有1个非0的数字。
输出描述:
在一行中输出能够组成的最小的数。
输入例子:
2 2 0 0 0 3 0 0 1 0
输出例子:
10015558
解题思路:
注意输出的描述,对应给定数字的内容
代码实现:
def main():
num_lsit = input().split(' ')
temp_list = []
for i in range(1,10):
temp = int(num_lsit[i])
while temp > 0:
temp_list.append(i)
temp = temp -1
if int(temp_list[0]) >0:
print(temp_list[0],end='')
temp = int(num_lsit[0])
while temp > 0:
print(0,end='')
temp = temp -1
for i in temp_list[1:]:
print(i,end='')
else:
for i in temp_list:
print(i,end='')
if __name__ =="__main__":
main()