petarkobakov

Inbox Manager

Aug 4th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Inbox_Manager
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Dictionary<string, List <string>> usersAndEmails = new Dictionary<string, List<string>>();
  13.  
  14. while (true)
  15. {
  16. string [] command = Console.ReadLine().Split("->");
  17. string operation = command[0];
  18.  
  19. if (operation == "Statistics")
  20. {
  21. break;
  22. }
  23.  
  24. else if (operation == "Add")
  25. {
  26. string user = command[1];
  27.  
  28. if (!usersAndEmails.ContainsKey(user))
  29. {
  30. usersAndEmails.Add(user, new List<string>());
  31. }
  32.  
  33. else
  34. {
  35. Console.WriteLine($"{user} is already registered");
  36. }
  37.  
  38. }
  39.  
  40. else if (operation == "Send")
  41. {
  42. string user = command[1];
  43. string email = command[2];
  44.  
  45. usersAndEmails[user].Add(email);
  46.  
  47. }
  48.  
  49. else if (operation == "Delete")
  50. {
  51. string user = command[1];
  52.  
  53. if (usersAndEmails.ContainsKey(user))
  54. {
  55. usersAndEmails.Remove(user);
  56. }
  57.  
  58. else
  59. {
  60. Console.WriteLine($"{user} not found!");
  61. }
  62.  
  63. }
  64. }
  65.  
  66. Console.WriteLine($"Users count: {usersAndEmails.Count}");
  67.  
  68.  
  69. var sorted = usersAndEmails.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key);
  70.  
  71. foreach (var user in sorted)
  72. {
  73.  
  74. Console.WriteLine(user.Key);
  75.  
  76. for (int i = 0; i < user.Value.Count; i++)
  77. {
  78. Console.WriteLine($"- {user.Value[i]}");
  79. }
  80.  
  81.  
  82. }
  83. }
  84. }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment