Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Judge {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- LinkedHashMap<String, TreeMap<String, Integer>> contests = new LinkedHashMap<>();
- TreeMap<String, Integer> users = new TreeMap<>();
- String input = sc.nextLine();
- while (!input.equals("no more time")) {
- String[] arr = input.split(" -> ");
- String user = arr[0];
- String contest = arr[1];
- int points = Integer.parseInt(arr[2]);
- contests.putIfAbsent(contest, new TreeMap<>());
- users.putIfAbsent(user, 0);
- if (contests.get(contest).containsKey(user)) {
- int setPoint = contests.get(contest).get(user);
- if (setPoint < points) {
- contests.get(contest).put(user, points);
- users.put(user, users.get(user) + (points - setPoint));
- }
- } else {
- contests.get(contest).put(user, points);
- if (users.containsKey(user)) {
- users.put(user, users.get(user) + points);
- }
- }
- input = sc.nextLine();
- }
- for (Map.Entry<String, TreeMap<String, Integer>> c : contests.entrySet()) {
- System.out.printf("%s: %d participants%n",
- c.getKey(), c.getValue().size());
- List<String> name = new ArrayList<>();
- List<Integer> points = new ArrayList<>();
- c.getValue()
- .entrySet()
- .stream()
- .sorted((c1, c2) -> {
- int first = c1.getValue();
- int second = c2.getValue();
- return Integer.compare(second, first);
- })
- .forEach(u -> {
- name.add(u.getKey());
- points.add(u.getValue());
- });
- for (int i = 0; i < name.size(); i++) {
- System.out.printf("%d. %s <::> %d%n", i + 1, name.get(i), points.get(i));
- }
- }
- System.out.println("Individual standings:");
- List<String> keysIndividual = new ArrayList<>();
- List<Integer> valuesIndividual = new ArrayList<>();
- users
- .entrySet()
- .stream()
- .sorted((u1, u2) -> Integer.compare(u2.getValue(), u1.getValue()))
- .forEach(u -> {
- keysIndividual.add(u.getKey());
- valuesIndividual.add(u.getValue());
- });
- for (int i = 0; i < keysIndividual.size(); i++) {
- System.out.printf("%d. %s -> %d%n", i + 1, keysIndividual.get(i), valuesIndividual.get(i));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement