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._1_FollowersWIthClass
- {
- class Program
- {
- static void Main()
- {
- string input = Console.ReadLine();
- Dictionary<string, Follower> followers = new Dictionary<string, Follower>();
- while (input != "Log out")
- {
- string[] tokens = input.Split(": ");
- string command = tokens[0];
- string username = tokens[1];
- switch (command)
- {
- case "New follower":
- if (!followers.ContainsKey(username))
- {
- Follower follower = new Follower()
- {
- Username = username,
- Likes = 0,
- Comments = 0
- };
- followers.Add(username, follower);
- }
- break;
- case "Like":
- int countLikes = int.Parse(tokens[2]);
- if (!followers.ContainsKey(username))
- {
- Follower follower = new Follower()
- {
- Username = username,
- Likes = 0,
- Comments = 0
- };
- followers.Add(username, follower);
- }
- followers[username].Likes += countLikes;
- break;
- case "Comment":
- if (!followers.ContainsKey(username))
- {
- Follower follower = new Follower()
- {
- Username = username,
- Likes = 0,
- Comments = 0
- };
- followers.Add(username, follower);
- }
- followers[username].Comments++;
- break;
- case "Blocked":
- if (followers.ContainsKey(username))
- {
- followers.Remove(username);
- }
- else
- {
- Console.WriteLine($"{username} doesn't exist.");
- }
- break;
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"{followers.Count} followers");
- foreach (var kvp in followers
- .OrderByDescending(followers => followers.Value.Likes)
- .ThenBy(followers => followers.Key))
- {
- Follower follower = kvp.Value;
- int sumOfLikesAndComments = follower.Likes + follower.Comments;
- Console.WriteLine($"{follower.Username}: {sumOfLikesAndComments}");
- }
- }
- public class Follower
- {
- public string Username { get; set; }
- public int Likes { get; set; }
- public int Comments { get; set; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement