Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class Judge {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, TreeMap<String, Integer>> contests = new LinkedHashMap<>();
- Map<String, Integer> users = new TreeMap<>();
- String input = scanner.nextLine();
- while (!input.equals("no more time")) {
- String[] tokens = input.split(" -> ");
- String username = tokens[0];
- String contestName = tokens[1];
- int points = Integer.parseInt(tokens[2]);
- if (!contests.containsKey(contestName)) {
- contests.put(contestName, new TreeMap<>());
- contests.get(contestName).put(username, points);
- } else if (contests.get(contestName).containsKey(username)
- && points > contests.get(contestName).get(username)) {
- contests.get(contestName).put(username, points);
- } else {
- contests.get(contestName).put(username, points);
- }
- input = scanner.nextLine();
- }
- if (!contests.isEmpty()) {
- contests.entrySet()
- .stream()
- .forEach(e -> {
- System.out.printf("%s: %d participants%n",
- e.getKey(), e.getValue().size());
- final int[] counter = {0};
- e.getValue().entrySet()
- .stream()
- .sorted((f, s) -> s.getValue() - f.getValue())
- .forEach(a -> {
- counter[0]++;
- System.out.printf("%d. %s <::> %d%n",
- counter[0], a.getKey(), a.getValue());
- });
- counter[0] = 0;
- });
- System.out.println("Individual standings:");
- contests.entrySet()
- .stream()
- .forEach(e -> {
- e.getValue().entrySet()
- .stream()
- .forEach(b -> {
- if (!users.containsKey(b.getKey())) {
- users.put(b.getKey(), b.getValue());
- } else {
- users.put(b.getKey(), users.get(b.getKey()) + b.getValue());
- }
- });
- });
- final int[] position = {1};
- users.entrySet().stream()
- .sorted((f, s) -> s.getValue() - f.getValue())
- .forEach(x -> {
- System.out.printf("%d. %s -> %d%n",
- position[0], x.getKey(), x.getValue());
- position[0]++;
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment