Advertisement
MZlatev

Untitled

Dec 2nd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _3._Followers
  6. {
  7. class Followers
  8. {
  9. static void Main()
  10. {
  11. Dictionary<string, List<int>> users = new Dictionary<string, List<int>>();
  12.  
  13. while (true)
  14. {
  15. string input = Console.ReadLine();
  16.  
  17. if (input == "Log out")
  18. {
  19. break;
  20. }
  21.  
  22. string[] splitedInput = input.Split(": ");
  23. string command = splitedInput[0];
  24. string username = splitedInput[1];
  25.  
  26. switch (command)
  27. {
  28. case "New follower":
  29.  
  30. if (!users.ContainsKey(username))
  31. {
  32. users.Add(username, new List<int>());
  33. users[username].Add(0);
  34. users[username].Add(0);
  35. }
  36.  
  37. break;
  38.  
  39. case "Like":
  40.  
  41. int count = int.Parse(splitedInput[2]);
  42.  
  43. if (!users.ContainsKey(username))
  44. {
  45. users.Add(username, new List<int>());
  46. users[username].Add(0);
  47. users[username].Add(0);
  48. }
  49.  
  50. users[username][0] += count;
  51.  
  52. break;
  53.  
  54. case "Comment":
  55.  
  56. if (!users.ContainsKey(username))
  57. {
  58. users.Add(username, new List<int>());
  59. users[username].Add(0);
  60. users[username].Add(0);
  61. }
  62.  
  63. users[username][1]++;
  64.  
  65. break;
  66.  
  67. case "Blocked":
  68.  
  69. if (!users.ContainsKey(username))
  70. {
  71. Console.WriteLine($"{username} doesn't exist.");
  72. }
  73.  
  74. else
  75. {
  76. users.Remove(username);
  77. }
  78.  
  79. break;
  80. }
  81. }
  82.  
  83. Console.WriteLine($"{users.Count} followers");
  84.  
  85. foreach (var name in users
  86. .OrderByDescending(x => x.Value[0])
  87. .ThenBy(x => x.Key))
  88. {
  89. int totalSum = name.Value[0] + name.Value[1];
  90.  
  91. Console.WriteLine($"{name.Key}: {totalSum}");
  92. }
  93.  
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement