Advertisement
roronoa

crypto compare

Apr 25th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.72 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Solution {
  6.  
  7.     public static void main(String args[]) {
  8.         Scanner in = new Scanner(System.in);
  9.         int N = in.nextInt();
  10.         if (in.hasNextLine()) {
  11.             in.nextLine();
  12.         }
  13.         String tab[] = new String[N];
  14.         for (int i = 0; i < N; i++)
  15.         {
  16.             tab[i] = in.nextLine();
  17.            
  18.         }
  19.         //Arrays.sort(tab, new StringComparator());
  20.         System.out.println(tab[0].split(" ")[0]);
  21.         //System.out.println("**GL**");
  22.     }
  23. }
  24. class StringComparator implements Comparator<String>
  25. {
  26.  
  27.     @Override
  28.     public int compare(String o1, String o2)
  29.     {
  30.             String t[] = o1.split(" ");
  31.             double avant = Double.parseDouble(t[1]);
  32.             double apres = Double.parseDouble(t[2]);
  33.             double fin1 = apres - avant;
  34.             String t2[] = o2.split(" ");
  35.             avant = Double.parseDouble(t2[1]);
  36.             apres = Double.parseDouble(t2[2]);
  37.             double fin2 = apres - avant;
  38.             //return Double.compare(fin1, fin2);
  39.             if(fin1 < fin2)
  40.                 return -1;
  41.             else if(fin2 < fin1)
  42.                 return 1;
  43.             else
  44.                 return 0;
  45.     }
  46. }
  47. /*
  48. import java.util.*;
  49. import java.io.*;
  50. import java.math.*;
  51.  
  52. class Solution {
  53.  
  54.     public static void main(String args[]) {
  55.         Scanner in = new Scanner(System.in);
  56.         int N = in.nextInt();
  57.         boolean fail = false;
  58.         List<Crypto> cryptos = new ArrayList<>();
  59.                if (in.hasNextLine()) {
  60.                 in.nextLine();
  61.             }
  62.         for (int i = 0; i < N; i++) {
  63.      
  64.             String crypto = in.nextLine();
  65.            // System.out.println(crypto);
  66.             String[] tab = crypto.split(" ");
  67.             if(tab.length == 3)
  68.             {
  69.                 Crypto cr = new Crypto(Double.parseDouble(tab[1]),Double.parseDouble(tab[2]),tab[0]);
  70.                 cryptos.add(cr);
  71.             }
  72.             else
  73.                 fail = true;
  74.            
  75.         }
  76.         if(fail == true)
  77.             System.out.println("NONE");
  78.         else
  79.         {
  80.             Collections.sort(cryptos);
  81.             System.out.println(cryptos.get(0).name);
  82.         }
  83.     }
  84.     static class Crypto implements Comparable<Crypto>
  85.     {
  86.         public double depart;
  87.         public double arrivee;
  88.         public String name;
  89.         public Crypto(double d, double a, String n)
  90.         {
  91.             depart = d;
  92.             arrivee = a;
  93.             name = n;
  94.         }
  95.         public int compareTo(Crypto o) {
  96.             return -1 * Double.compare(arrivee / depart, o.arrivee / o.depart);
  97.         }
  98.     }
  99. }
  100. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement