SHOW:
|
|
- or go back to the newest paste.
| 1 | - | package exams.retakeApril; |
| 1 | + | |
| 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.Map; | |
| 9 | ||
| 10 | - | import java.util.HashSet; |
| 10 | + | public class Veronika {
|
| 11 | public static void main(String[] args) throws IOException {
| |
| 12 | BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
| 13 | - | public class P04_WormWorldParty {
|
| 13 | + | |
| 14 | String input = ""; | |
| 15 | ||
| 16 | Map<String, ArrayList<Pair<String, Integer>>> map = new HashMap<>(); | |
| 17 | Map<String, Integer> sumTeamScore = new HashMap<>(); | |
| 18 | ||
| 19 | while (true) {
| |
| 20 | - | //ArrayList<Pair<String, Integer>> list = new ArrayList<>(); |
| 20 | + | |
| 21 | if ("quit".equals(input)) break;
| |
| 22 | ||
| 23 | String[] tokens = input.split(" -> ");
| |
| 24 | ||
| 25 | String name = tokens[0]; | |
| 26 | String team = tokens[1]; | |
| 27 | int score = Integer.parseInt(tokens[2]); | |
| 28 | ||
| 29 | if (!map.containsKey(team)) {
| |
| 30 | map.put(team, new ArrayList<>()); | |
| 31 | map.get(team).add(new Pair<>(name, score)); | |
| 32 | ||
| 33 | sumTeamScore.put(team, score); | |
| 34 | } else {
| |
| 35 | boolean contains = doesContain(map, team, name); | |
| 36 | ||
| 37 | if (!contains) {
| |
| 38 | map.get(team).add(new Pair<>(name, score)); | |
| 39 | - | for (int i = 0; i < map.get(team).size(); i++) {
|
| 39 | + | |
| 40 | - | if (!(map.get(team).get(i).getKey().equals(name))) {
|
| 40 | + | |
| 41 | - | map.get(team).add(new Pair<>(name, score)); |
| 41 | + | |
| 42 | System.out.println(); | |
| 43 | - | int sum = sumTeamScore.get(team) + score; |
| 43 | + | |
| 44 | - | sumTeamScore.put(team, sum); |
| 44 | + | |
| 45 | - | } |
| 45 | + | private static boolean doesContain(Map<String, ArrayList<Pair<String, Integer>>> map, String team, String name) {
|
| 46 | for (int i = 0; i < map.get(team).size(); i++) {
| |
| 47 | if (map.get(team).get(i).getKey().equals(name)) | |
| 48 | return true; | |
| 49 | } | |
| 50 | ||
| 51 | return false; | |
| 52 | } | |
| 53 | } |