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