Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.lang.reflect.Array;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- Map<String, Map<String, Integer>> book = new TreeMap<>();
- Map<String, Integer> pointMap = new TreeMap<>();
- String input = reader.readLine();
- while (!input.equalsIgnoreCase("exam finished")) {
- String[] data = input.split("-");
- String name = data[0];
- String language = data[1];
- if (!language.equalsIgnoreCase("banned")) {
- int points = Integer.parseInt(data[2]);
- book.putIfAbsent(name, new TreeMap<>());
- book.get(name).put(language, points);
- } else {
- book.putIfAbsent(name, new TreeMap<>());
- book.get(name).putIfAbsent("banned", 0);
- }
- pointMap.putIfAbsent(language, 0);
- pointMap.put(language, pointMap.get(language) + 1);
- input = reader.readLine();
- }
- System.out.println("Results:");
- book.entrySet()
- .stream()
- .filter(x -> !x.getValue().containsKey("banned"))
- .sorted((a, b) -> Integer.compare(b.getValue().values().stream().mapToInt(y -> y).max().getAsInt(), a.getValue().values().stream().mapToInt(y -> y).max().getAsInt()))
- .forEach(x -> {
- int maxPoints = x.getValue().values().stream().mapToInt(y -> y).max().getAsInt();
- System.out.printf("%s | %d\n", x.getKey(), maxPoints);
- });
- System.out.println("Submissions:");
- pointMap.entrySet()
- .stream()
- .filter(x -> !x.getKey().equals("banned"))
- .sorted((a, b) -> Integer.compare(b.getValue(), a.getValue()))
- .forEach(x -> {
- System.out.printf("%s - %d\n", x.getKey(), x.getValue());
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement