Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PastFinalExams.finexam;
- import java.util.*;
- public class Inbox {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, List<String>> usersInfo = new LinkedHashMap<>();
- Map<String, Integer> sentEmails = new LinkedHashMap<>();
- String command;
- while (!(command = scanner.nextLine()).equals("Statistics")) {
- String[] tokens = command.split("->");
- String subCommand = tokens[0];
- String username = tokens[1];
- int sentCount = 0;
- switch (subCommand) {
- case "Add":
- if (usersInfo.containsKey(username)) {
- System.out.println(String.format("%s is already registered", username));
- } else {
- usersInfo.put(username, new ArrayList<>());
- }
- /*List<String> sentEmails = usersInfo.get(username);
- if (!sentEmails.contains(usersInfo.get(username))) {
- sentEmails.add(username);
- }
- */
- break;
- case "Send":
- String email = tokens[2];
- sentEmails.put(username, 1);
- List<String> sentList = usersInfo.get(username);
- usersInfo.get(username).add(email);
- break;
- case "Delete":
- if (usersInfo.containsKey(username)) {
- usersInfo.remove(username);
- } else {
- System.out.println(String.format("%s not found!", username));
- }
- break;
- }
- }
- System.out.println(String.format("Users count: %d", usersInfo.size()));
- sentEmails
- .entrySet()
- .stream()
- .sorted((a, b) -> {
- int result = b.getValue().compareTo(a.getValue());
- if (result == 0) {
- result = a.getKey().compareTo(b.getKey());
- }
- return result;
- }).forEach(e -> {
- System.out.println(e.getKey());
- });
- for (String user : usersInfo) {
- System.out.println(String.format("- %s", sentEmails));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement