petarkobakov

Followers

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