Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace ConsoleApp13
- {
- class Program
- {
- static void Main(string[] args)
- {
- string text = string.Empty;
- Dictionary<string,int[]> nameViewLikes = new Dictionary<string,int[]>();
- while ((text = Console.ReadLine()) != "stats time")
- {
- if (text.Contains('-'))
- {
- string[] nameAndViews = text.Split("-").ToArray();
- string videoName = nameAndViews[0];
- int view = int.Parse(nameAndViews[1]);
- if (!nameViewLikes.ContainsKey(videoName))
- {
- nameViewLikes.Add(videoName,new int[2]);
- nameViewLikes[videoName][0] += view;
- }
- else
- {
- nameViewLikes[videoName][0]+=view;
- }
- }
- else if (text.Contains(":"))
- {
- string[] likesAndVideos = text.Split(":").ToArray();
- if (likesAndVideos[0] == "like")
- {
- string command = likesAndVideos[0];
- string name = likesAndVideos[1];
- if (nameViewLikes.ContainsKey(name))
- {
- nameViewLikes[name][1]++;
- }
- }
- else if (likesAndVideos[0] == "dislike")
- {
- string command = likesAndVideos[0];
- string name = likesAndVideos[1];
- if (nameViewLikes.ContainsKey(name))
- {
- nameViewLikes[name][1]--;
- }
- }
- }
- }
- string orderCriterion = Console.ReadLine();
- if (orderCriterion == "by views")
- {
- foreach (var item in nameViewLikes.OrderByDescending(x => x.Value[0]))
- {
- Console.WriteLine($"{item.Key} - {item.Value[0]} views - {item.Value[1]} likes");
- }
- }
- else if (orderCriterion == "by likes")
- {
- foreach (var item in nameViewLikes.OrderByDescending(x => x.Value[1]))
- {
- Console.WriteLine($"{item.Key} - {item.Value[0]} views - {item.Value[1]} likes");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement