Advertisement
nikolapetkov824

metubeStats

Dec 11th, 2018
78
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.Text;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. namespace ExamPrepMeTubeStatistics
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Dictionary<string, int[]> videoStatistics =
  13.                 new Dictionary<string, int[]>();
  14.  
  15.             while (true)
  16.             {
  17.                 string input = Console.ReadLine();
  18.  
  19.                 if (input=="stats time")
  20.                 {
  21.                     break;
  22.                 }
  23.                 else
  24.                 {
  25.                     if (input.Contains("-"))
  26.                     {
  27.                         string[] videoStats = input.Split("-");
  28.                         string video = videoStats[0];
  29.                         int views = int.Parse(videoStats[1]);
  30.  
  31.                         if (videoStatistics.ContainsKey(video) == false)
  32.                         {
  33.                             videoStatistics.Add(video, new int[2]);
  34.                             //videoStatistics[video][1] = views;
  35.                         }
  36.                         videoStatistics[video][1] += views;
  37.                     }
  38.                     else if (input.Contains(":"))
  39.                     {
  40.                         string[] videoStats = input.Split(":");
  41.                         string likesDislikes = videoStats[0];
  42.                         string video = videoStats[1];
  43.  
  44.                         if (likesDislikes == "like")
  45.                         {
  46.                             if (videoStatistics.ContainsKey(video))
  47.                             {
  48.                                 videoStatistics[video][0]++;
  49.                             }
  50.                         }
  51.                         else if (likesDislikes == "dislike")
  52.                         {
  53.                             if (videoStatistics.ContainsKey(video))
  54.                             {
  55.                                 videoStatistics[video][0]--;
  56.                             }
  57.                         }
  58.                     }
  59.                 }
  60.             }
  61.  
  62.             string sortCommand = Console.ReadLine();
  63.  
  64.             if (sortCommand=="by views")
  65.             {
  66.                 foreach (var video in videoStatistics.OrderByDescending(x => x.Value[1]))
  67.                 {
  68.                     Console.WriteLine($"{video.Key} - {video.Value[1]} views - {video.Value[0]} likes");
  69.                 }
  70.             }
  71.             else
  72.             {
  73.                 foreach (var video in videoStatistics.OrderByDescending(x => x.Value[0]))
  74.                 {
  75.                     Console.WriteLine($"{video.Key} - {video.Value[1]} views - {video.Value[0]} likes");
  76.                 }
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement