Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Messages_Manager
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int capacity = int.Parse(Console.ReadLine());
  12.  
  13. Dictionary<string, List<int>> users = new Dictionary<string, List<int>>();
  14.  
  15. string command = Console.ReadLine();
  16.  
  17. while (command != "Statistics")
  18. {
  19. string[] cmd = command.Split("=", StringSplitOptions.RemoveEmptyEntries);
  20.  
  21. if (cmd[0] == "Add")
  22. {
  23. if (!users.ContainsKey(cmd[1]))
  24. {
  25. users.Add(cmd[1], new List<int>());
  26. users[cmd[1]].Add(int.Parse(cmd[2]));
  27. users[cmd[1]].Add(int.Parse(cmd[3]));
  28. }
  29. }
  30. if (cmd[0] == "Message")
  31. {
  32. string firstUser = cmd[1];
  33. string secndUser = cmd[2];
  34.  
  35. if (users.ContainsKey(firstUser) && users.ContainsKey(secndUser))
  36. {
  37. users[firstUser][0]++;
  38. users[secndUser][1]++;
  39. if (users[firstUser].Sum() >= capacity)
  40. {
  41. users.Remove(firstUser);
  42. Console.WriteLine($"{firstUser} reached the capacity!");
  43. }
  44. if (users[secndUser].Sum() >= capacity)
  45. {
  46. users.Remove(secndUser);
  47. Console.WriteLine($"{secndUser} reached the capacity!");
  48. }
  49. }
  50.  
  51. }
  52. if (cmd[0] == "Empty")
  53. {
  54. if (cmd[1] == "All")
  55. {
  56. users.Clear();
  57. }
  58. else
  59. {
  60. if (users.ContainsKey(cmd[1]))
  61. {
  62. users.Remove(cmd[1]);
  63. }
  64. }
  65. }
  66.  
  67. command = Console.ReadLine();
  68. }
  69.  
  70. Console.WriteLine($"Users count: {users.Count}");
  71. foreach (var user in users.OrderByDescending(u => u.Value[1]).ThenBy(x => x.Key))
  72. {
  73. int sum = user.Value.Sum();
  74. Console.WriteLine($"{user.Key} - {sum}");
  75. }
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement