Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Followers
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string input = Console.ReadLine();
  12. Dictionary<string, List<int>> followerWithLikes = new Dictionary<string, List<int>>();
  13.  
  14. while (input!="Log out")
  15. {
  16. string[] splitedInput = input.Split(": ").ToArray();
  17. string command = splitedInput[0];
  18. string user = splitedInput[1];
  19.  
  20. if (command == "New follower")
  21. {
  22. if (!followerWithLikes.ContainsKey(user))
  23. {
  24. followerWithLikes.Add(user, new List<int>());
  25. }
  26. else
  27. {
  28.  
  29. }
  30. }
  31. else if (command == "Like")
  32. {
  33. int count = int.Parse(splitedInput[2]);
  34. if (!followerWithLikes.ContainsKey(user))
  35. {
  36. followerWithLikes.Add(user, new List<int>());
  37. followerWithLikes[user].Add(count);
  38. }
  39. else
  40. {
  41. followerWithLikes[user].Add(count);
  42. }
  43. }
  44. else if (command == "Comment")
  45. {
  46. if (!followerWithLikes.ContainsKey(user))
  47. {
  48. followerWithLikes.Add(user, new List<int>());
  49. followerWithLikes[user].Add(1);
  50. }
  51. else
  52. {
  53. followerWithLikes[user].Add(1);
  54. }
  55. }
  56. else if (command == "Blocked")
  57. {
  58. if (!followerWithLikes.ContainsKey(user))
  59. {
  60. Console.WriteLine($"{user} doesn't exist.");
  61. }
  62. else
  63. {
  64. followerWithLikes.Remove(user);
  65. }
  66. }
  67. input = Console.ReadLine();
  68. }
  69. Console.WriteLine(followerWithLikes.Keys.Count+ " followers");
  70.  
  71. followerWithLikes = followerWithLikes.OrderByDescending(x => x.Value.Sum()).ThenBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
  72.  
  73. foreach (var user in followerWithLikes)
  74. {
  75. int count = user.Value.Sum();
  76. Console.WriteLine($"{user.Key}: {count}");
  77. }
  78. }
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement