Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03.Followers_s_methods
- {
- class Follower
- {
- public Follower(string name, int likes, int comments)
- {
- Name = name;
- Likes = likes;
- Comments = comments;
- }
- public string Name { get; set; }
- public int Likes { get; set; }
- public int Comments { get; set; }
- public override string ToString()
- {
- return $"{this.Name}: {this.Likes + this.Comments}";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Follower> followers = new List<Follower>();
- string input;
- while ((input = Console.ReadLine()) != "Log out")
- {
- string[] splitted = input.Split(":");
- string command = splitted[0];
- string user = splitted[1];
- switch (command)
- {
- case "New follower":
- if (followers.Find(x => x.Name == user) == null)
- {
- Follower follower = new Follower(user, +0, +0);
- followers.Add(follower);
- }
- break;
- case "Like":
- int likes = int.Parse(splitted[2]);
- if (followers.Find(x => x.Name == user) == null)
- {
- Follower follower = new Follower(user, +likes, +0);
- followers.Add(follower);
- }
- else
- {
- followers.Find(x => x.Name == user).Likes += likes;
- }
- break;
- case "Comment":
- if (followers.Find(x => x.Name == user) == null)
- {
- Follower follower = new Follower(user, +0, +1);
- followers.Add(follower);
- }
- else
- {
- followers.Find(x => x.Name == user).Comments += 1;
- }
- break;
- case "Blocked":
- if (!(followers.Find(x => x.Name == user) == null))
- {
- followers = followers.FindAll(x => x.Name != user);
- }
- break;
- }
- }
- Console.WriteLine($"{followers.Count} followers");
- List<Follower> sorted = followers.OrderByDescending(l => l.Likes).ThenBy(n => n.Name).ToList();
- Console.WriteLine(String.Join("\n", sorted));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement