Advertisement
mastersan12

MeTube Statistics

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