Advertisement
desislava_topuzakova

Untitled

Nov 3rd, 2023
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  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 LinkedHashMap<>();
  10. // language -> count
  11. Map<String, Integer> languageCount = new LinkedHashMap<>();
  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()
  47. .forEach(e -> System.out.println(e.getKey() + " | " + e.getValue()));
  48.  
  49. System.out.println("Submissions:");
  50. languageCount.entrySet()
  51. .forEach(e -> System.out.println(e.getKey() + " - " + e.getValue()));
  52.  
  53.  
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement