Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace P05.MeTube_Statistics
- {
- class Program
- {
- static void Main(string[] args)
- {
- var videos = new Dictionary<string, int>();
- var rating = new Dictionary<string, int>();
- string input = string.Empty;
- while ((input = Console.ReadLine()) != "stats time")
- {
- if (input.IndexOf("-") >= 0)
- {
- var command1 = input.Split("-");
- string video = command1[0];
- int views = int.Parse(command1[1]);
- if (!videos.ContainsKey(video))
- {
- videos.Add(video, views);
- }
- else
- {
- videos[video] += views;
- }
- }
- else
- {
- var command2 = input.Split(":");
- string likeORdislike = command2[0];
- string video = command2[1];
- if (!rating.ContainsKey(video))
- {
- if (likeORdislike == "like")
- {
- rating.Add(video, +1);
- }
- else
- {
- rating.Add(video, -1);
- }
- }
- else
- {
- if (likeORdislike == "like")
- {
- rating[video] += 1;
- }
- else
- {
- rating[video] -= 1;
- }
- }
- }
- }
- string lastInput = Console.ReadLine();
- if (lastInput == "by views")
- {
- foreach (var video in videos.OrderByDescending(x=>x.Value))
- {
- foreach (var likes in rating)
- {
- Console.WriteLine($"{video.Key} - {video.Value} views - {likes.Value} likes");
- }
- }
- }
- else
- {
- foreach (var item in rating.OrderByDescending(x=>x.Value))
- {
- foreach (var video in videos)
- {
- Console.WriteLine($"{video.Key} - {video.Value} views - {item.Value} likes");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement