Advertisement
Guest User

Untitled

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