Guest User

Untitled

a guest
Apr 1st, 2020
1,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. sing System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace MessagesManager2
  6. {
  7. public class Info
  8. {
  9. public int send { get; set; }
  10. public int received { get; set; }
  11. }
  12.  
  13. internal class Program
  14. {
  15. private static void Main(string[] args)
  16. {
  17. Dictionary<string, Info> pairs = new Dictionary<string, Info>();
  18. int maxCapacity = int.Parse(Console.ReadLine());
  19. string input = Console.ReadLine();
  20.  
  21. while (input != "Statistics")
  22. {
  23. string[] array = input.Split('=');
  24. string action = array[0];
  25. if (action.Equals("Add", StringComparison.InvariantCulture))
  26. {
  27. string username = array[1];
  28. int sent = int.Parse(array[2]);
  29. int received = int.Parse(array[3]);
  30. if (!pairs.ContainsKey(username))
  31. {
  32. pairs.Add(username, new Info());
  33. pairs[username].send = sent;
  34. pairs[username].received = received;
  35. }
  36. }
  37. else if (action.Equals("Empty", StringComparison.InvariantCulture))
  38. {
  39. string userName = array[1];
  40. if (userName.Equals("All", StringComparison.InvariantCulture))
  41. {
  42. pairs.Clear();
  43. }
  44. else if (pairs.ContainsKey(userName))
  45. {
  46. pairs.Remove(userName);
  47. }
  48. }
  49. else if (action.Equals("Message", StringComparison.InvariantCulture))
  50. {
  51. string sender = array[1];
  52. string receiver = array[2];
  53. if (pairs.ContainsKey(sender) && pairs.ContainsKey(receiver))
  54. {
  55. pairs[sender].send += 1;
  56. pairs[receiver].received += 1;
  57. if (pairs[sender].send + pairs[sender].received >= maxCapacity)
  58. {
  59. Console.WriteLine("{0} reached the capacity!", sender);
  60. pairs.Remove(sender);
  61. }
  62. if (pairs[receiver].send + pairs[receiver].received >= maxCapacity)
  63. {
  64. Console.WriteLine("{0} reached the capacity!", receiver);
  65. pairs.Remove(receiver);
  66. }
  67. }
  68. }
  69. input = Console.ReadLine();
  70. }
  71. Console.WriteLine($"Users count: {pairs.Count}");
  72. foreach (KeyValuePair<string, Info> kvp in pairs.OrderByDescending(p => p.Value.received).ThenBy(p => p.Key))
  73. {
  74. Console.WriteLine($"{kvp.Key} - {kvp.Value.received + kvp.Value.send}");
  75. }
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment