Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Messages_Manager
  6. {
  7. public class Status
  8. {
  9. public int Sent { get; set; }
  10. public int Recived { get; set; }
  11.  
  12. public Status(int sent, int recived)
  13. {
  14. this.Sent = sent;
  15. this.Recived = recived;
  16. }
  17. public int Total => this.Sent + this.Recived;
  18.  
  19. }
  20. class Program
  21. {
  22. static void Main()
  23. {
  24. int capacity = int.Parse(Console.ReadLine());
  25.  
  26. Dictionary<string, Status> peopleStatus = new Dictionary<string, Status>();
  27. while (true)
  28. {
  29. string input = Console.ReadLine();
  30. if (input == "Statistics")
  31. {
  32. break;
  33. }
  34. string[] cmdArgs = input.Split("=");
  35. string cmd = cmdArgs[0];
  36. if (cmd == "Add")
  37. {
  38. string username = cmdArgs[1];
  39. int sent = int.Parse(cmdArgs[2]);
  40. int recived = int.Parse(cmdArgs[3]);
  41.  
  42. if (!peopleStatus.ContainsKey(username))
  43. {
  44. peopleStatus.Add(username, new Status(sent, recived));
  45. }
  46. }
  47. else if (cmd == "Message")
  48. {
  49. string sender = cmdArgs[1];
  50. string reciver = cmdArgs[2];
  51.  
  52. if (peopleStatus.ContainsKey(sender) && peopleStatus.ContainsKey(reciver))
  53. {
  54. peopleStatus[sender].Sent++;
  55. peopleStatus[reciver].Recived++;
  56. if (peopleStatus[sender].Total >= capacity)
  57. {
  58. peopleStatus.Remove(sender);
  59. Console.WriteLine($"{sender} reached the capacity!");
  60. }
  61. if (peopleStatus[reciver].Total >= capacity)
  62. {
  63. peopleStatus.Remove(reciver);
  64. Console.WriteLine($"{reciver} reached the capacity!");
  65. }
  66. }
  67. }
  68. else if (cmd == "Empty")
  69. {
  70. string username = cmdArgs[1];
  71. if (username == "All")
  72. {
  73. peopleStatus = new Dictionary<string, Status>();
  74. }
  75. else if (peopleStatus.ContainsKey(username))
  76. {
  77. peopleStatus.Remove(username);
  78. }
  79. }
  80. }
  81. Console.WriteLine($"Users count: {peopleStatus.Count}");
  82. foreach (var people in peopleStatus.OrderByDescending(x => x.Value.Recived).ThenBy(x => x.Key))
  83. {
  84. Console.WriteLine($"{people.Key} - {people.Value.Total}");
  85. }
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement