Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.HashMap;
- import java.util.LinkedHashMap;
- import java.util.Scanner;
- public class Judge {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine();
- HashMap<String, LinkedHashMap<String, Integer>> contests = new LinkedHashMap<>();
- HashMap<String, Integer> users = new LinkedHashMap<>();
- while (!input.toLowerCase().equals("no more time")) {
- String[] tokens = input.split(" -> ");
- String username = tokens[0];
- String contest = tokens[1];
- Integer points = Integer.parseInt(tokens[2]);
- if (contests.containsKey(contest)) {
- if (contests.get(contest).containsKey(username)) {
- int currPoints = contests.get(contest).get(username);
- if (points > currPoints) {
- contests.get(contest).put(username, points);
- users.put(username, users.get(username) + points - currPoints);
- }
- } else {
- contests.get(contest).put(username, points);
- if (users.get(username) == null) {
- users.put(username, 0);
- }
- int cPoints = users.get(username);
- int pointsToAdd = cPoints + points;
- users.put(username, pointsToAdd);
- }
- } else {
- contests.put(contest, new LinkedHashMap<>());
- contests.get(contest).put(username, points);
- if (users.get(username) == null) {
- users.put(username, 0);
- }
- users.put(username, users.get(username) + points);
- }
- input = sc.nextLine();
- }
- var ref = new Object() {
- int counter = 0;
- };
- contests.entrySet().stream().forEach(a -> {
- System.out.printf("%s: %d participants%n", a.getKey(), a.getValue().size());
- a.getValue().entrySet().stream().sorted((f, s) -> {
- int result = s.getValue().compareTo(f.getValue());
- if (result == 0) {
- result = f.getKey().compareTo(s.getKey());
- }
- return result;
- })
- .forEach(c -> {
- ref.counter++;
- System.out.printf("%d. %s <::> %d%n", ref.counter, c.getKey(), c.getValue());
- });
- ref.counter = 0;
- });
- System.out.println("Individual standings:");
- users.entrySet().stream().sorted((f, s) -> {
- int result = s.getValue().compareTo(f.getValue());
- if (result == 0) {
- result = f.getKey().compareTo(s.getKey());
- }
- return result;
- })
- .forEach(c -> {
- ref.counter++;
- System.out.printf("%d. %s -> %d%n", ref.counter, c.getKey(), c.getValue());
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement