Advertisement
ss3434

Untitled

Mar 9th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Inbox_Manager
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var userName= new Dictionary<string, List<String>>();
  12. var usermsg= new Dictionary<string, List<String>>();
  13.  
  14. int userCount = 0;
  15. string[] comand = Console.ReadLine().Split("->").ToArray();
  16. while (comand[0] != "Statistics")
  17. {
  18. if (comand[0]=="Add")
  19. {
  20. string name=comand[1];
  21. if (userName.ContainsKey(name))
  22. {
  23. Console.WriteLine($"{name} is already registered");//ako go ima
  24. }
  25. else if (!userName.ContainsKey(name))///ako ne sadarja KEY
  26. {
  27. userName[name] = new List<string>();//syzdavame KEY
  28.  
  29. userCount += 1;//BROIM KEY
  30.  
  31. }
  32. userName[name].Add(name);
  33.  
  34. }
  35. else if (comand[0] == "Send")
  36. {
  37. string name = comand[1];
  38. string email = comand[2];
  39. if (userName.ContainsKey(name))
  40. {
  41. if (!usermsg.ContainsKey(name))
  42. {
  43. usermsg[name] = new List<string>();
  44.  
  45. }
  46. usermsg[name].Add(email);
  47.  
  48. }
  49.  
  50. }
  51. else if (comand[0] == "Delete")
  52. {
  53. string name = comand[1];
  54. if (userName.ContainsKey(name))//ako sydarja key
  55. {
  56. userName.Remove(name);//triene na KEY
  57. usermsg.Remove(name);
  58. userCount--;//namalqme broq4a
  59. }
  60. else
  61. {
  62. Console.WriteLine($"{name} not found!");
  63. }
  64.  
  65. }
  66. comand = Console.ReadLine().Split("->").ToArray();
  67. }
  68.  
  69. Console.WriteLine($"Users count: {userCount}");//userName.Keys.Count
  70. //Console.WriteLine($"Users count: {userName.Keys.Count}");
  71.  
  72. usermsg = usermsg.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
  73. foreach (var item in usermsg)
  74. {
  75. Console.WriteLine($"{item.Key}");
  76. Console.WriteLine($" - {string.Join(Environment.NewLine + " - ",item.Value)}");
  77. }
  78. }
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement