Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _04MeTubeStatistics
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> videoViews = new Dictionary<string, int>();
- Dictionary<string, int> videoLikes = new Dictionary<string, int>();
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "stats time")
- {
- break;
- }
- if (command.Contains('-'))
- {
- string[] tokens = command.Split('-');
- string video = tokens[0];
- int views = int.Parse(tokens[1]);
- if (!videoViews.ContainsKey(video))
- {
- videoViews[video] = 0;
- videoLikes[video] = 0;
- }
- videoViews[video] += views;
- }
- else if (command.Contains(':'))
- {
- string[] tokens = command.Split(':');
- string action = tokens[0];
- string video = tokens[1];
- if (action == "like")
- {
- if (!videoLikes.ContainsKey(video))
- {
- videoLikes.Add(video, 1);
- }
- else
- {
- videoLikes[video] += 1;
- }
- }
- else if (action == "dislike")
- {
- if (!videoLikes.ContainsKey(video))
- {
- videoLikes.Add(video, -1);
- }
- else
- {
- videoLikes[video] -= 1;
- }
- }
- }
- }
- string criterion = Console.ReadLine();
- if (criterion== "by views")
- {
- foreach (var kvp in videoViews.OrderByDescending(x=>x.Value))
- {
- string video = kvp.Key;
- int views = kvp.Value;
- int likes = videoLikes[video];
- Console.WriteLine($"{video} - {views} views - {likes} likes");
- }
- }
- else
- {
- foreach (var kvp in videoLikes.OrderByDescending(x=>x.Value))
- {
- string video = kvp.Key;
- int likes = kvp.Value;
- int views = videoViews[video];
- Console.WriteLine($"{video} - {views} views - {likes} likes");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement