l = input()
x = input()
xlist = x.split()
xlist = [int(xlist[i]) for i in range(int(l))]
xlist.sort(key = lambda z:(z%10 , -z))
for j in range(int(l)):
print(xlist[j], end=' ')
l = input()
x = input()
xlist = x.split()
xlist = [int(xlist[i]) for i in range(int(l))]
xlist.sort(key = lambda z:(z%10 , -z))
for j in range(int(l)):
print(xlist[j], end=' ')
輸入說明 第一行:有多組測試資料,以 EOF 結束。
所以你要多一層迴圈,不能只輸入一組資料就結束