Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package AssociativeArraysExercise;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.HashMap;
- import java.util.Map;
- public class MOBAChallenger {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- Map<String, Map<String, Integer>> playersByPositionBySkill = new HashMap<>();
- Map<String, Integer> totalSkill = new HashMap<>();
- String line = reader.readLine();
- while (!line.equals("Season end")){
- if (line.contains(" -> ")){
- String[] tokens = line.split(" -> ");
- String player = tokens[0];
- String position = tokens[1];
- int skill = Integer.parseInt(tokens[2]);
- playersByPositionBySkill.putIfAbsent(player, new HashMap<>());
- if (!playersByPositionBySkill.get(player).containsKey(position)){
- playersByPositionBySkill.get(player).put(position,skill);
- totalSkill.put(player,skill);
- } else {
- if (playersByPositionBySkill.get(player).get(position) < skill){
- playersByPositionBySkill.get(player).put(position,skill);
- }
- totalSkill.put(player, totalSkill.get(player) + skill);
- }
- } else if (line.contains("vs")){
- String[] tokens = line.split(" vs ");
- String playerOne = tokens[0];
- String playerTwo = tokens[1];
- if (playersByPositionBySkill.containsKey(playerOne) && playersByPositionBySkill.containsKey(playerTwo)){
- if (totalSkill.get(playerOne).equals(totalSkill.get(playerTwo))){
- if (totalSkill.get(playerOne) < totalSkill.get(playerTwo)){
- totalSkill.remove(playerOne);
- } else {
- totalSkill.remove(playerTwo);
- }
- }
- }
- }
- line = reader.readLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement