Advertisement
Rayk

Untitled

Mar 1st, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import javafx.util.Pair;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7. import java.util.HashMap;
  8. import java.util.HashSet;
  9. import java.util.Map;
  10.  
  11. public class Veronika {
  12. public static void main(String[] args) throws IOException {
  13. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  14.  
  15. String input = "";
  16.  
  17. Map<String, ArrayList<Pair<String, Integer>>> map = new HashMap<>();
  18. Map<String, Integer> sumTeamScore = new HashMap<>();
  19.  
  20. while (true) {
  21. input = reader.readLine();
  22. if ("quit".equals(input)) break;
  23.  
  24. String[] tokens = input.split(" -> ");
  25.  
  26. String name = tokens[0];
  27. String team = tokens[1];
  28. int score = Integer.parseInt(tokens[2]);
  29.  
  30. boolean contains = doesContain(map, name);
  31.  
  32. if (contains)
  33. continue;
  34.  
  35. if (!map.containsKey(team)) {
  36. map.put(team, new ArrayList<>());
  37. map.get(team).add(new Pair<>(name, score));
  38.  
  39. sumTeamScore.put(team, score);
  40. } else {
  41. map.get(team).add(new Pair<>(name, score));
  42. }
  43. }
  44. System.out.println();
  45. }
  46.  
  47. private static boolean doesContain(Map<String, ArrayList<Pair<String, Integer>>> map, String name) {
  48. for (Map.Entry<String, ArrayList<Pair<String, Integer>>> entry : map.entrySet()) {
  49. for (Pair<String, Integer> pair : entry.getValue()) {
  50. if (pair.getKey().equals(name))
  51. return true;
  52. }
  53. }
  54.  
  55. return false;
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement