Advertisement
Edzhevit

MOBA Chalenger

Nov 27th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. package AssociativeArraysExercise;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8.  
  9. public class MOBAChallenger {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  12.  
  13.         Map<String, Map<String, Integer>> playersByPositionBySkill = new HashMap<>();
  14.         Map<String, Integer> totalSkill = new HashMap<>();
  15.  
  16.         String line = reader.readLine();
  17.  
  18.         while (!line.equals("Season end")){
  19.             if (line.contains(" -> ")){
  20.                 String[] tokens = line.split(" -> ");
  21.                 String player = tokens[0];
  22.                 String position = tokens[1];
  23.                 int skill = Integer.parseInt(tokens[2]);
  24.  
  25.                 playersByPositionBySkill.putIfAbsent(player, new HashMap<>());
  26.                 if (!playersByPositionBySkill.get(player).containsKey(position)){
  27.                     playersByPositionBySkill.get(player).put(position,skill);
  28.                     totalSkill.put(player,skill);
  29.  
  30.                 } else {
  31.                     if (playersByPositionBySkill.get(player).get(position) < skill){
  32.                         playersByPositionBySkill.get(player).put(position,skill);
  33.                     }
  34.                     totalSkill.put(player, totalSkill.get(player) + skill);
  35.                 }
  36.  
  37.             } else if (line.contains("vs")){
  38.                 String[] tokens = line.split(" vs ");
  39.                 String playerOne = tokens[0];
  40.                 String playerTwo = tokens[1];
  41.  
  42.                 if (playersByPositionBySkill.containsKey(playerOne) && playersByPositionBySkill.containsKey(playerTwo)){
  43.                     if (totalSkill.get(playerOne).equals(totalSkill.get(playerTwo))){
  44.                         if (totalSkill.get(playerOne) < totalSkill.get(playerTwo)){
  45.                             totalSkill.remove(playerOne);
  46.                         } else {
  47.                             totalSkill.remove(playerTwo);
  48.                         }
  49.                     }
  50.                 }
  51.  
  52.             }
  53.  
  54.             line  = reader.readLine();
  55.         }
  56.  
  57.  
  58.  
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement