Advertisement
bullit3189

MeTubeStatistics-FinalExam-Dictionary

Mar 14th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  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. string action = tokens[0];
  27. string songName = tokens[1];
  28.  
  29. if (action == "like")
  30. {
  31. if (videoLikes.ContainsKey(songName))
  32. {
  33. videoLikes[songName]+=1;
  34. }
  35.  
  36. }
  37. else
  38. {
  39. if (videoLikes.ContainsKey(songName))
  40. {
  41. videoLikes[songName]-=1;
  42. }
  43. }
  44. }
  45. else
  46. {
  47. string[] tokens = command.Split('-');
  48.  
  49. string songName = tokens[0];
  50. int views = int.Parse(tokens[1]);
  51.  
  52. if (!videoViews.ContainsKey(songName))
  53. {
  54. videoViews.Add(songName,views);
  55. videoLikes.Add(songName,0);
  56. }
  57. else
  58. {
  59. videoViews[songName]+=views;
  60. }
  61. }
  62. }
  63.  
  64. string criterion = Console.ReadLine();
  65.  
  66. if (criterion == "by views")
  67. {
  68. foreach (var kvp in videoViews.OrderByDescending(x=>x.Value))
  69. {
  70. string name = kvp.Key;
  71. int views = kvp.Value;
  72. int likes = videoLikes[name];
  73.  
  74. Console.WriteLine("{0} - {1} views - {2} likes",name,views,likes);
  75. }
  76. }
  77. else
  78. {
  79. foreach (var kvp in videoLikes.OrderByDescending(x=>x.Value))
  80. {
  81. string name = kvp.Key;
  82. int likes = kvp.Value;
  83. int views = videoViews[name];
  84.  
  85. Console.WriteLine("{0} - {1} views - {2} likes",name,views,likes);
  86. }
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement