Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class group_Qnislav_InboxManager {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- HashMap<String, List<String>> map = new HashMap<>();
- //int counter = 0;
- while (!input.equals("Statistics")) {
- String[] command = input.split("->");
- String action = command[0];
- String username = command[1];
- switch (action) {
- case "Add":
- if (map.containsKey(username)) {
- System.out.printf("%s is already registered%n", username);
- } else {
- map.put(username, new ArrayList<>());
- //counter++;
- }
- break;
- case "Send":
- String email = command[2];
- if (map.containsKey(username)) {
- map.get(username).add(email);
- }
- break;
- case "Delete":
- if (map.containsKey(username)) {
- map.remove(username);
- // counter--;
- } else {
- System.out.printf("%s not found!%n", username);
- }
- break;
- }
- input = scanner.nextLine();
- }
- System.out.printf("Users count: %d%n",map.keySet().size());
- map
- .entrySet()
- .stream()
- .sorted((a,b)->{
- int first = a.getValue().size();
- int second = b.getValue().size();
- int compare = second-first;
- if(compare==0){
- compare = a.getKey().compareTo(b.getKey());
- }
- return compare;
- })
- .forEach(a->{
- System.out.println(a.getKey());
- a.getValue()
- .forEach(b -> System.out.printf("- %s%n",b));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement