Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Programming_Fundamentals.L12_Final_Exams.F00Final_Exam;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class E03InboxManager {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- TreeMap<String, List<String>> map = new TreeMap<>();
- String[] input = sc.nextLine().split("->");
- while (!input[0].equals("Statistics")) {
- switch (input[0]) {
- case "Add":
- if (map.containsKey(input[1])) {
- System.out.printf("%s is already registered%n", input[1]);
- } else {
- map.put(input[1], new ArrayList<>());
- }
- break;
- case "Send":
- if (map.containsKey(input[1])) {
- map.get(input[1]).add(input[2]);
- }
- break;
- case "Delete":
- if (map.containsKey(input[1])) {
- map.remove(input[1]);
- } else {
- System.out.printf("%s not found!%n", input[1]);
- }
- break;
- }
- input = sc.nextLine().split("->");
- }
- System.out.printf("Users count: %d%n", map.size());
- map.entrySet().stream()
- .sorted((e1, e2) -> e2.getValue().size() - e1.getValue().size())
- .forEach(entry -> {
- System.out.println(entry.getKey());
- entry.getValue().forEach(s -> System.out.printf(" - %s%n", s));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement