Advertisement
roronoa

teams comparator

Apr 24th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. class Solution {
  2.  
  3.     public static void main(String args[]) {
  4.         Scanner in = new Scanner(System.in);
  5.         int n = in.nextInt();
  6.         Team tab[] = new Team[n];
  7.         for (int i = 0; i < n; i++) {
  8.             String s = in.next();
  9.             int p = in.nextInt();
  10.             int x = in.nextInt();
  11.             int y = in.nextInt();
  12.             tab[i] = new Team(s,p,(int) Math.max(x, y) - (int) Math.min(x, y),x);
  13.         }
  14.         Arrays.sort(tab, new TeamComparator());
  15.         System.out.println(tab[tab.length-1].teamName);
  16.     }
  17. }
  18.  
  19.  
  20. class Team
  21. {
  22.     public String teamName;
  23.     public int totalPoints;
  24.     public int differenceGoals;
  25.     public int goals;
  26.     public Team()
  27.     {}
  28.     public Team(String teamName, int totalPoints, int differenceGoals, int goals)
  29.     {
  30.         this.teamName = teamName;
  31.         this.totalPoints = totalPoints;
  32.         this.differenceGoals = differenceGoals;
  33.         this.goals = goals;
  34.     }
  35. }
  36. class TeamComparator implements Comparator<Team>
  37. {
  38.  
  39.     @Override
  40.     public int compare(Team o1, Team o2)
  41.     {
  42.         int retour = Integer.compare(o1.totalPoints, o2.totalPoints);
  43.         if(retour == 0)
  44.             retour = Integer.compare(o1.differenceGoals, o2.differenceGoals);
  45.         if(retour == 0)
  46.             retour = Integer.compare(o1.goals, o2.goals);
  47.  
  48.         return retour;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement