当前位置:网站首页>PTA 1056 sum of combinations (15 points)

PTA 1056 sum of combinations (15 points)

2022-06-24 05:11:00 freesan44

subject

Given N A non 0 A digit number of , Use any of them 2 Both numbers can be combined into 1 individual 2 Digit number . Require all possible combinations 2 The sum of digits . For example, given 2、5、8, You can combine :25、28、52、58、82、85, Their sum is 330.

Input format :

The input is given first in one line N(1 < N < 10), Subsequently given N A different non 0 One digit number . Numbers are separated by spaces .

Output format :

Output all possible combinations 2 The sum of digits .

 sample input :
3 2 8 5
 No blank lines at the end 
 sample output :
330
 No blank lines at the end 

Their thinking

inputList = list(input().split())
# inputList = list("3 2 8 5".split())
count = int(inputList.pop(0))
res = 0
for index1, val1 in enumerate(inputList):
    for index2, val2 in enumerate(inputList):
        if index1 != index2:
            # Turn one digit into ten Str Turn into int
            res = res + int(str(val1+val2))
print(res)
原网站

版权声明
本文为[freesan44]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/08/20210821221256993g.html