Advertisement
damesova

SoftUni Exam Results [Mimi]

Mar 17th, 2019
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class _10_SoftUniExamResults {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         Map<String, Integer> peopleRes = new HashMap<>();
  8.         Map<String, Integer> submits = new HashMap<>();
  9.         String input = "";
  10.         while (!"exam finished".equals(input = scanner.nextLine())) {
  11.             String[] line = input.split("-");
  12.  
  13.             if (line.length == 3) {
  14.                 String name = line[0];
  15.                 String language = line[1];
  16.                 int points = Integer.parseInt(line[2]);
  17.                 if (!peopleRes.containsKey(name)) {
  18.                     peopleRes.put(name, points);
  19.                 } else if (peopleRes.get(name) < points) {
  20.                     peopleRes.put(name, points);
  21.                 }
  22.  
  23.                 if (!submits.containsKey(language)) {
  24.                     submits.put(language, 1);
  25.                 } else {
  26.                     submits.put(language, submits.get(language) + 1);
  27.                 }
  28.             } else {
  29.                 peopleRes.remove(line[0]);
  30.             }
  31.  
  32.         }
  33.  
  34.         System.out.println("Results:");
  35.         peopleRes.entrySet().stream()
  36.                 .sorted(Map.Entry.<String, Integer>comparingByValue()
  37.                         .reversed()
  38.                         .thenComparing(Map.Entry.comparingByKey()))
  39.                 .forEach(entry -> {
  40.                     System.out.println(String.format("%s | %d",
  41.                             entry.getKey(), entry.getValue()));
  42.                 });
  43.  
  44.         System.out.println("Submissions:");
  45.         submits.entrySet().stream()
  46.                 .sorted(Map.Entry.<String, Integer>comparingByValue()
  47.                         .reversed()
  48.                         .thenComparing(Map.Entry.comparingByKey()))
  49.                 .forEach(entry -> {
  50.                     System.out.println(String.format("%s - %d",
  51.                             entry.getKey(), entry.getValue()));
  52.                 });
  53.  
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement