Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _3._Followers
- {
- class Followers
- {
- static void Main()
- {
- Dictionary<string, List<int>> users = new Dictionary<string, List<int>>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Log out")
- {
- break;
- }
- string[] splitedInput = input.Split(": ");
- string command = splitedInput[0];
- string username = splitedInput[1];
- switch (command)
- {
- case "New follower":
- if (!users.ContainsKey(username))
- {
- users.Add(username, new List<int>());
- users[username].Add(0);
- users[username].Add(0);
- }
- break;
- case "Like":
- int count = int.Parse(splitedInput[2]);
- if (!users.ContainsKey(username))
- {
- users.Add(username, new List<int>());
- users[username].Add(0);
- users[username].Add(0);
- }
- users[username][0] += count;
- break;
- case "Comment":
- if (!users.ContainsKey(username))
- {
- users.Add(username, new List<int>());
- users[username].Add(0);
- users[username].Add(0);
- }
- users[username][1]++;
- break;
- case "Blocked":
- if (!users.ContainsKey(username))
- {
- Console.WriteLine($"{username} doesn't exist.");
- }
- else
- {
- users.Remove(username);
- }
- break;
- }
- }
- Console.WriteLine($"{users.Count} followers");
- foreach (var name in users
- .OrderByDescending(x => x.Value[0])
- .ThenBy(x => x.Key))
- {
- int totalSum = name.Value[0] + name.Value[1];
- Console.WriteLine($"{name.Key}: {totalSum}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement