python大数处理

题目描述
Today, ZLZX has a mysterious case: Orange lost his down jacket hanging in his dorm room. Under the expectations of everyone, detective Groundhog took his small spoon of the artifact and started the journey to solve the case.

After an in-depth investigation of the northernmost mysterious room on each floor, Groundhog discovered {n}n mysterious numbers. As long as the clues conveyed by these numbers are deciphered, he can reveal the truth of the matter. The deciphering method is: using these numbers to generate two positive integers without leading zeros, and minimizing the product of these two positive integers is the final clue.

Then Groundhog wants to know: What is the smallest product?

As he continued to investigate in the room west of the new building, he gave you the question.

Concise meaning:Given n numbers between 0 and 9, use them to make two positive integers without leading zeros to minimize the product.
输入描述:
The first line of input is a single integer {T}T,the number of test cases.
For each set of data:
Each test case begins with a single integer {n}n , the count of numbers.
The next line are {n}n numbers.
输出描述:
For each set of Case, an integer is output, representing the smallest product.

示例1
输入 1 4 1 2 2 1
输出 122

示例2
输入 2 5 1 3 2 1 2 3 1 1 0
输出
1223 10

num = int(input())
for i in range(num):
    n = int(input())
    res = 0
    op =input().split()//op直接默认为list
    op.sort()
    while op[res]=='0':
       res+=1
    s=op[res+1]+'0'*res+"".join(op[res+2:])
    //join()中的参数必须是字符串类型,而iuput默认返回值是string,即list为string类型,所以可以直接进行join操作
    ans = int(s)*int(op[res])
    print(ans)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值