Advertisement
Guest User

Untitled

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