fork(4) download
  1. // if (howManyPoint==1){
  2. // System.out.println(list.get(0).nazwa + " " + list.get(0).x + " " + list.get(0).y);
  3. // continue;
  4. // }
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.Scanner;
  8.  
  9. public class Main {
  10. public static void main(String[] args) {
  11.  
  12. Scanner scanner = new Scanner(System.in);
  13. int howManyTries = scanner.nextInt();
  14. scanner.nextLine();
  15. for (int i = 0; i < howManyTries; i++) {
  16.  
  17. int howManyPoint = scanner.nextInt();
  18. scanner.nextLine();
  19. List<Punkt> list = new ArrayList<>();
  20. for (int j = 0; j <howManyPoint ; j++) {
  21.  
  22. String point = scanner.nextLine();
  23. String[] tableofPoints = point.split(" ");
  24. Punkt punkt = new Punkt(tableofPoints[0], Integer.parseInt(tableofPoints[1]), Integer.parseInt(tableofPoints[2]));
  25. list.add(punkt);
  26. }
  27. list.sort(new PunktComparator());
  28.  
  29.  
  30. for(Punkt number : list) {
  31.  
  32. System.out.println(number.nazwa + " " + number.x + " " + number.y);
  33.  
  34. }
  35. System.out.println();
  36. }
  37. }
  38. }
  39. class Punkt {
  40. public String nazwa;
  41. int x;
  42. int y;
  43. double odleglosc;
  44. Punkt(String nazwa, int x, int y){
  45. this.nazwa = nazwa;
  46. this.x = x;
  47. this.y = y;
  48. odleglosc = Math.sqrt(x*x+y*y);
  49. }
  50. public int odleglosc() {
  51. return (int)odleglosc;
  52. }
  53. }
  54. class PunktComparator implements java.util.Comparator<Punkt> {
  55. @Override
  56. public int compare(Punkt a, Punkt b) {
  57. return a.odleglosc() - b.odleglosc();
  58. }
  59. }
Success #stdin #stdout 0.21s 60944KB
stdin
4
1
X 1 1

3
A 0 0    
C 5 5
B 1 -1  

3
D 9 17    
E 5 5    
F 5 -5    

3
x 8 -5
w 4 -5
a 3 3
stdout
X 1 1

A 0 0
B 1 -1
C 5 5

E 5 5
F 5 -5
D 9 17

a 3 3
w 4 -5
x 8 -5