Advertisement
roronoa

classement gares station (pas sûr que ça marche tho)

Aug 22nd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Solution {
  6.     public static int xStation;
  7.     public static int yStation;
  8.     public static void main(String args[])
  9.     {
  10.         Scanner in = new Scanner(System.in);
  11.         int N = in.nextInt();
  12.         Gare[] gares = new Gare[N-1];
  13.         int index = 0;
  14.         for (int i = 0; i < N; i++)
  15.         {
  16.             String place = in.next();
  17.             int X = in.nextInt();
  18.             int Y = in.nextInt();
  19.             if(place.equals("station"))
  20.             {
  21.                 xStation = X;
  22.                 yStation = Y;
  23.             }
  24.             else
  25.                 gares[index++] = new Gare(place, X, Y);
  26.         }
  27.         Arrays.sort(gares, new GareComparator());
  28.         String rep = "";
  29.         for(Gare gare : gares)
  30.             rep += gare.name + " ";
  31.         System.out.println(rep.trim());
  32.  
  33.     }
  34.     static class Gare
  35.     {
  36.         public String name;
  37.         public int x;
  38.         public int y;
  39.         public Gare(String name, int x, int y)
  40.         {
  41.             this.name = name;
  42.             this.x = x;
  43.             this.y =y;
  44.         }
  45.  
  46.     }
  47.     public static class GareComparator implements Comparator<Gare>
  48.     {
  49.         @Override
  50.         public int compare(Gare gare1, Gare gare2)
  51.         {
  52.             float gare1aStation = (gare1.x-xStation)*(gare1.x-xStation) + (gare1.y-yStation)*(gare1.y-yStation);
  53.             float gare2aStation = (gare2.x-xStation)*(gare2.x-xStation) + (gare2.y-yStation)*(gare2.y-yStation);
  54.             return new Float(gare1aStation).compareTo(new Float(gare2aStation));
  55.         }
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement