desislava_topuzakova

10. SoftUni Exam Results

Mar 7th, 2021
804
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.sun.security.jgss.GSSUtil;
  2.  
  3. import java.util.*;
  4.  
  5. public class demo {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         //username -> points
  9.         Map<String, Integer> userPoints = new HashMap<>();
  10.         // language -> count
  11.         Map<String, Integer> languageCount = new HashMap<>();
  12.         String input = scanner.nextLine();
  13.  
  14.         while (!input.equals("exam finished")) {
  15.             String[] splitArray = input.split("-");
  16.             //1. "{username}-{language}-{points}" -> ["{username}", "{language}", "{points}"]
  17.             //2. "{username}-banned" -> ["{username}", "banned"]
  18.             String username = splitArray[0];
  19.             if (splitArray.length == 3) {
  20.                 String language = splitArray[1];
  21.                 int points = Integer.parseInt(splitArray[2]);
  22.                 //добавяме username и точки
  23.                 if (!userPoints.containsKey(username)) {
  24.                     userPoints.put(username, points);
  25.                 } else {
  26.                     int currentPoints = userPoints.get(username);
  27.                     if (points > currentPoints) {
  28.                         userPoints.put(username, points);
  29.                     }
  30.                 }
  31.  
  32.                 //добавяме брой срещания на езика
  33.                 if (!languageCount.containsKey(language)) {
  34.                     languageCount.put(language, 1);
  35.                 } else {
  36.                     languageCount.put(language, languageCount.get(language) + 1);
  37.                 }
  38.  
  39.             } else {
  40.                 userPoints.remove(username);
  41.             }
  42.             input = scanner.nextLine();
  43.         }
  44.  
  45.         System.out.println("Results:");
  46.         userPoints.entrySet().stream()
  47.                 .sorted(Map.Entry.<String, Integer>comparingByValue().reversed()
  48.                         .thenComparing(Map.Entry.comparingByKey()))
  49.                 .forEach(e -> System.out.println(e.getKey() + " | " + e.getValue()));
  50.  
  51.         System.out.println("Submissions:");
  52.         languageCount.entrySet().stream()
  53.                 .sorted(Map.Entry.<String, Integer>comparingByValue().reversed()
  54.                         .thenComparing(Map.Entry.comparingByKey()))
  55.                 .forEach(e -> System.out.println(e.getKey() + " - " + e.getValue()));
  56.  
  57.  
  58.     }
  59. }
  60.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×