Vote count:
0
I study python and I have task difficult for me.
Task: Input 2 string:
5
2 3 9 2 9
Sample Output:
2 2 3 9 9
I know how to sort it, but I have trouble with input. Test-case input used stdin. I write this:
import sys
input = sys.stdin.read()
tokens = input.split()
n = int(tokens[0])
A = tokens[1:len(tokens)]
B = []
M = 10
for i in range(M):
B.append(0)
for j in range(n):
B[int(A[j])] = B[int(A[j])] + 1
k = 0
for i in range(M):
for j in range(B[i]):
A[k] = i
k = k + 1
print(A)
and get error "out range" for B[int(A[j])] = B[int(A[j])] + 1
asked 12 secs ago
Aucun commentaire:
Enregistrer un commentaire