Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. Programming_Fundamentals.L12_Final_Exams.F00Final_Exam;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6. import java.util.TreeMap;
  7.  
  8. public class E03InboxManager {
  9. public static void main(String[] args) {
  10. Scanner sc = new Scanner(System.in);
  11.  
  12. TreeMap<String, List<String>> map = new TreeMap<>();
  13. String[] input = sc.nextLine().split("->");
  14.  
  15. while (!input[0].equals("Statistics")) {
  16.  
  17. switch (input[0]) {
  18. case "Add":
  19. if (map.containsKey(input[1])) {
  20. System.out.printf("%s is already registered%n", input[1]);
  21. } else {
  22. map.put(input[1], new ArrayList<>());
  23. }
  24. break;
  25.  
  26. case "Send":
  27. if (map.containsKey(input[1])) {
  28. map.get(input[1]).add(input[2]);
  29. }
  30. break;
  31.  
  32. case "Delete":
  33. if (map.containsKey(input[1])) {
  34. map.remove(input[1]);
  35. } else {
  36. System.out.printf("%s not found!%n", input[1]);
  37. }
  38. break;
  39. }
  40.  
  41. input = sc.nextLine().split("->");
  42. }
  43.  
  44. System.out.printf("Users count: %d%n", map.size());
  45.  
  46. map.entrySet().stream()
  47. .sorted((e1, e2) -> e2.getValue().size() - e1.getValue().size())
  48. .forEach(entry -> {
  49. System.out.println(entry.getKey());
  50.  
  51. entry.getValue().forEach(s -> System.out.printf(" - %s%n", s));
  52. });
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement