Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Followers
- {
- class Follower
- {
- public Follower(int likes=0, int comments=0)
- {
- Likes = likes;
- Comments = comments;
- }
- public int Likes { get; set; }
- public int Comments { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Follower> followers =
- new Dictionary<string, Follower>();
- string command = Console.ReadLine();
- while (command != "Log out")
- {
- string[] split = command.Split(": ");
- if (command.Contains("New follower"))
- {
- if (!followers.ContainsKey(split[1]))
- {
- followers.Add(split[1], new Follower());
- }
- }
- if (command.Contains("Like"))
- {
- int likes = int.Parse(split[2]);
- if (!followers.ContainsKey(split[1]))
- {
- followers.Add(split[1],new Follower(likes));
- }
- else
- {
- followers[split[1]].Likes += likes;
- }
- }
- if (command.Contains("Comment"))
- {
- if (!followers.ContainsKey(split[1]))
- {
- followers.Add(split[1], new Follower(0,1));
- }
- else
- {
- followers[split[1]].Comments += 1;
- }
- }
- if (command.Contains("Blocked"))
- {
- if (followers.ContainsKey(split[1]))
- {
- followers.Remove(split[1]);
- }
- else
- {
- Console.WriteLine($"{split[1]} doesn't exist.");
- }
- }
- command = Console.ReadLine();
- }
- Console.WriteLine($"{followers.Count} followers");
- followers = followers
- .OrderByDescending(f => f.Value.Likes)
- .ThenBy(f => f.Key)
- .ToDictionary(f => f.Key, f=> f.Value);
- foreach (var follower in followers)
- {
- Console.WriteLine($"{follower.Key}: {follower.Value.Likes + follower.Value.Comments}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement