Advertisement
bullit3189

MeTube Statistics - Exam-Dictionary-28Oct18

Jan 29th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _04MeTubeStatistics
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, int> videoViews = new Dictionary<string, int>();
  12. Dictionary<string, int> videoLikes = new Dictionary<string, int>();
  13.  
  14. while (true)
  15. {
  16. string command = Console.ReadLine();
  17.  
  18. if (command == "stats time")
  19. {
  20. break;
  21. }
  22.  
  23. if (command.Contains('-'))
  24. {
  25. string[] tokens = command.Split('-');
  26.  
  27. string video = tokens[0];
  28. int views = int.Parse(tokens[1]);
  29.  
  30. if (!videoViews.ContainsKey(video))
  31. {
  32. videoViews[video] = 0;
  33. videoLikes[video] = 0;
  34. }
  35.  
  36. videoViews[video] += views;
  37. }
  38. else if (command.Contains(':'))
  39. {
  40. string[] tokens = command.Split(':');
  41.  
  42. string action = tokens[0];
  43. string video = tokens[1];
  44.  
  45. if (action == "like")
  46. {
  47. if (!videoLikes.ContainsKey(video))
  48. {
  49.  
  50. videoLikes.Add(video, 1);
  51. }
  52. else
  53. {
  54. videoLikes[video] += 1;
  55. }
  56. }
  57. else if (action == "dislike")
  58. {
  59. if (!videoLikes.ContainsKey(video))
  60. {
  61. videoLikes.Add(video, -1);
  62. }
  63. else
  64. {
  65.  
  66. videoLikes[video] -= 1;
  67. }
  68. }
  69. }
  70. }
  71.  
  72. string criterion = Console.ReadLine();
  73.  
  74. if (criterion== "by views")
  75. {
  76. foreach (var kvp in videoViews.OrderByDescending(x=>x.Value))
  77. {
  78. string video = kvp.Key;
  79. int views = kvp.Value;
  80. int likes = videoLikes[video];
  81.  
  82. Console.WriteLine($"{video} - {views} views - {likes} likes");
  83. }
  84. }
  85. else
  86. {
  87. foreach (var kvp in videoLikes.OrderByDescending(x=>x.Value))
  88. {
  89. string video = kvp.Key;
  90. int likes = kvp.Value;
  91. int views = videoViews[video];
  92.  
  93. Console.WriteLine($"{video} - {views} views - {likes} likes");
  94. }
  95. }
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement