fork download
  1. import math
  2. def byDistance(elem):
  3. name,x,y,distance = elem.split()
  4. return float(distance)
  5. t = int(input())
  6. r = []
  7. for i in range(0,t):
  8. r.append([])
  9. k = int(input())
  10. for e in range(0,k):
  11. name,x,y = input().split()
  12. distance = math.sqrt(math.pow(int(x), 2) + math.pow(int(y), 2))
  13. r[i].append("{} {} {} {}".format(name,x,y,distance))
  14. r[i].sort(key=byDistance)
  15. if i != t-1:
  16. input()
  17. for i in range(0,len(r)):
  18. for e in range(0,len(r[i])):
  19. print(r[i][e].replace(str(byDistance(r[i][e])),""))
  20. print()
Success #stdin #stdout 0.04s 9564KB
stdin
3
9
A 1 1
B 3 3
C 2 2
D 5 5
E 4 4
F 7 7
G 6 6
H 9 9
I 8 8

3
X 5 -5
Y 2 2
Z 1 1

4
Ax 10 10
Bx 10 9
Cx 8 10
Dx 11 7
stdout
A 1 1 
C 2 2 
B 3 3 
E 4 4 
D 5 5 
G 6 6 
F 7 7 
I 8 8 
H 9 9 

Z 1 1 
Y 2 2 
X 5 -5 

Cx 8 10 
Dx 11 7 
Bx 10 9 
Ax 10 10