Advertisement
MZlatev

Untitled

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