分別對 k 個陣列進行排序并將它們連接起來。輸入說明:第一行包含陣列的數量。隨后的行包含陣列的大小,后跟陣列的元素。
輸出描述:一個包含k個排序陣列的排序元素的陣列
樣品輸入:3 2 98 12 6 1 2 3 8 5 9 1 11 樣品輸出:12 98 1 2 3 5 8 9 11
a=input()
b=input()
c= input().split()
C=str(sorted(c))
d=input()
e=input().split()
E=str(sorted(e))
f=input()
g=input().split()
G=str(sorted(g))
x=C E G
print(*x)````
#output
[ ' 1 2 ' , ' 9 8 ' ] [ ' 1 ' , ' 2 ' , ' 3 ' , ' 5 ' , ' 8 ' , ' 9 ' ] [ ' 1 1 ' ]````
`desired output`
#i want my output as
Sample Output :
12 98 1 2 3 5 8 9 11
uj5u.com熱心網友回復:
import re
val = "[ ' 1 2 ' , ' 9 8 ' ] [ ' 1 ' , ' 2 ' , ' 3 ' , ' 5 ' , ' 8 ' , ' 9 ' ] [ ' 1 1 ' ]"
print(re.sub(r'[^\w]', ' ', val))
我相信它適合你。
uj5u.com熱心網友回復:
x = C E G
x = x.replace('[', '').replace(']', ' ').replace("'", '').replace(',', '')
print(x)
希望它會作業
uj5u.com熱心網友回復:
如果我正確理解了您的問題,那么您無需將串列轉換為字串。
a=input() # Number of arrays (let's say 3)
b=input() # Length of first array (let's say 3)
c= list(map(int, input().split())) # read a list of integer from user
# C=str(sorted(c)) this line is a bug. sorting on strings (i.e. 100 is bigger than 2)
c.sort() # here we sorted a list of integers which is correct
d=input() # length of second array (let's say 6)
e= list(map(int, input().split())) # again reading list of integers
# E=str(sorted(e)) # again a bug. Sorting the strings
e.sort() # sorting list of INT
f=input() # length of 3rd array (let's say 1)
g= list(map(int, input().split())) # reading list of INT
# G=str(sorted(g)) # again a bug : )
g.sort()
x = c e g # ' ' operator on a list concatenates them
print(*x)
樣本輸入:
3
3
3 2 1
6
6 5 4 3 2 1
1
1
輸出:
1 2 3 1 2 3 4 5 6 1
這應該可以正常作業。干杯。!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/532458.html
標籤:Python排序
上一篇:按動態鍵對多維陣列進行排序
