Advertisement
MZlatev

Untitled

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