Advertisement
svetlyoek

Untitled

Apr 10th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ConsoleApp13
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string text = string.Empty;
  13. Dictionary<string,int[]> nameViewLikes = new Dictionary<string,int[]>();
  14.  
  15. while ((text = Console.ReadLine()) != "stats time")
  16. {
  17. if (text.Contains('-'))
  18. {
  19. string[] nameAndViews = text.Split("-").ToArray();
  20. string videoName = nameAndViews[0];
  21. int view = int.Parse(nameAndViews[1]);
  22. if (!nameViewLikes.ContainsKey(videoName))
  23. {
  24. nameViewLikes.Add(videoName,new int[2]);
  25. nameViewLikes[videoName][0] += view;
  26.  
  27. }
  28. else
  29. {
  30. nameViewLikes[videoName][0]+=view;
  31.  
  32. }
  33. }
  34. else if (text.Contains(":"))
  35. {
  36.  
  37. string[] likesAndVideos = text.Split(":").ToArray();
  38. if (likesAndVideos[0] == "like")
  39. {
  40. string command = likesAndVideos[0];
  41. string name = likesAndVideos[1];
  42. if (nameViewLikes.ContainsKey(name))
  43. {
  44.  
  45. nameViewLikes[name][1]++;
  46. }
  47. }
  48. else if (likesAndVideos[0] == "dislike")
  49. {
  50. string command = likesAndVideos[0];
  51. string name = likesAndVideos[1];
  52. if (nameViewLikes.ContainsKey(name))
  53. {
  54.  
  55. nameViewLikes[name][1]--;
  56. }
  57. }
  58. }
  59. }
  60. string orderCriterion = Console.ReadLine();
  61. if (orderCriterion == "by views")
  62. {
  63. foreach (var item in nameViewLikes.OrderByDescending(x => x.Value[0]))
  64. {
  65. Console.WriteLine($"{item.Key} - {item.Value[0]} views - {item.Value[1]} likes");
  66. }
  67. }
  68. else if (orderCriterion == "by likes")
  69. {
  70. foreach (var item in nameViewLikes.OrderByDescending(x => x.Value[1]))
  71. {
  72. Console.WriteLine($"{item.Key} - {item.Value[0]} views - {item.Value[1]} likes");
  73. }
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement