Advertisement
silvana1303

inbox manager

Aug 7th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _02._Boss_Rush
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string[] command = Console.ReadLine().Split("->");
  13.  
  14.             Dictionary<string, List<string>> message = new Dictionary<string, List<string>>();
  15.  
  16.             while (command[0] != "Statistics")
  17.             {
  18.                 if (command[0] == "Add")
  19.                 {
  20.                     if (message.ContainsKey(command[1]))
  21.                     {
  22.                         Console.WriteLine($"{command[1]} is already registered");
  23.                     }
  24.                     else
  25.                     {
  26.                         message[command[1]] = new List<string>();
  27.                     }
  28.                 }
  29.                 if (command[0] == "Send")
  30.                 {
  31.                     message[command[1]].Add(command[2]);
  32.                 }
  33.                 if (command[0] == "Delete")
  34.                 {
  35.                     if (message.ContainsKey(command[1]))
  36.                     {
  37.                         message.Remove(command[1]);
  38.                     }
  39.                     else
  40.                     {
  41.                         Console.WriteLine($"{command[1]} not found!");
  42.                     }
  43.                 }
  44.  
  45.                 command = Console.ReadLine().Split("->");
  46.             }
  47.  
  48.             Console.WriteLine($"Users count: {message.Count}");
  49.  
  50.             foreach (var item in message.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
  51.             {
  52.                 Console.WriteLine($"{item.Key}");
  53.                 foreach (var kvp in item.Value)
  54.                 {
  55.                     Console.WriteLine($"- {kvp}");
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement