fork(4) download
  1. import math
  2. n = int(input())
  3. r = []
  4. res = []
  5. i = 0
  6. while n > 0:
  7. k = int(input())
  8. res.append([])
  9. while k > 0:
  10. name, x, y = input().split()
  11. x = int(x)
  12. y = int(y)
  13. distance = math.sqrt(math.pow(x, 2) + math.pow(y, 2))
  14. if len(r) > 0:
  15. for e in range(0,len(r)):
  16. if distance < r[e]:
  17. r.insert(e, distance)
  18. res[i].insert(e, "{} {} {}".format(name, x, y))
  19. break
  20. elif e == len(r)-1:
  21. r.append(distance)
  22. res[i].append("{} {} {}".format(name, x, y))
  23. elif distance > r[i]:
  24. continue
  25. else:
  26. r.append(distance)
  27. res[i].append("{} {} {}".format(name, x, y))
  28. k -= 1
  29. n -= 1
  30. if n > 0:
  31. print()
  32. i += 1
  33. del r[:]
  34. for e in range(0,i):
  35. print("\n".join(res[e]))
  36. if e != len(res)-1:
  37. print()
Success #stdin #stdout 0.03s 9536KB
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