Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- public class Program
- {
- public static void Main()
- {
- 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 action = tokens[0];
- string songName = tokens[1];
- if (action == "like")
- {
- if (videoLikes.ContainsKey(songName))
- {
- videoLikes[songName]+=1;
- }
- }
- else
- {
- if (videoLikes.ContainsKey(songName))
- {
- videoLikes[songName]-=1;
- }
- }
- }
- else
- {
- string[] tokens = command.Split('-');
- string songName = tokens[0];
- int views = int.Parse(tokens[1]);
- if (!videoViews.ContainsKey(songName))
- {
- videoViews.Add(songName,views);
- videoLikes.Add(songName,0);
- }
- else
- {
- videoViews[songName]+=views;
- }
- }
- }
- string criterion = Console.ReadLine();
- if (criterion == "by views")
- {
- foreach (var kvp in videoViews.OrderByDescending(x=>x.Value))
- {
- string name = kvp.Key;
- int views = kvp.Value;
- int likes = videoLikes[name];
- Console.WriteLine("{0} - {1} views - {2} likes",name,views,likes);
- }
- }
- else
- {
- foreach (var kvp in videoLikes.OrderByDescending(x=>x.Value))
- {
- string name = kvp.Key;
- int likes = kvp.Value;
- int views = videoViews[name];
- Console.WriteLine("{0} - {1} views - {2} likes",name,views,likes);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement