Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _07._The_V_Logger
- {
- class Program
- {
- static void Main(string[] args)
- {
- HashSet<Vlogger> vloggers = new HashSet<Vlogger>();
- string input = Console.ReadLine();
- while (input != "Statistics")
- {
- string[] commandParts = input.Split(" ",
- StringSplitOptions.RemoveEmptyEntries);
- string name = commandParts[0];
- string command = commandParts[1];
- switch (command)
- {
- case "joined":
- bool isExists = IsVloggerExists(vloggers, name);
- if (isExists)
- {
- break;
- }
- else
- {
- vloggers.Add(new Vlogger(name));
- }
- break;
- case "followed":
- string followed = commandParts[2];
- bool isVloggerExists = IsVloggerExists(vloggers, name);
- bool isFollowedExists = IsVloggerExists(vloggers, followed);
- bool isFollowing = IsFollowing(vloggers, name, followed);
- if (isVloggerExists
- && isFollowedExists
- && name != followed
- && isFollowing == false)
- {
- foreach (var vlogger in vloggers)
- {
- if (vlogger.Name == name)
- {
- vlogger.Following.Add(followed);
- }
- if (vlogger.Name == followed)
- {
- vlogger.Followers.Add(name);
- }
- }
- }
- break;
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"The V-Logger has a total of {vloggers.Count} vloggers in its logs.");
- int counter = 1;
- foreach (var vlogger in vloggers
- .OrderByDescending(vlogger => vlogger.Followers.Count)
- .ThenBy(vlogger => vlogger.Following.Count))
- {
- Console.WriteLine($"{counter}. {vlogger.Name} : " +
- $"{vlogger.Followers.Count} followers, " +
- $"{vlogger.Following.Count} following");
- if (counter == 1)
- {
- foreach (var follower in vlogger.Followers.OrderBy(x => x))
- {
- Console.WriteLine($"* {follower}");
- }
- }
- counter++;
- }
- }
- private static bool IsFollowing(HashSet<Vlogger> vloggers, string name, string followed)
- {
- foreach (var vlogger in vloggers)
- {
- if (vlogger.Name == name)
- {
- if (vlogger.Following.Contains(followed))
- {
- return true;
- }
- }
- }
- return false;
- }
- private static bool IsVloggerExists(HashSet<Vlogger> vloggers, string name)
- {
- bool isExists = false;
- foreach (var vlogger in vloggers)
- {
- if (vlogger.Name == name)
- {
- isExists = true;
- break;
- }
- }
- return isExists;
- }
- }
- public class Vlogger
- {
- public Vlogger(string name)
- {
- Name = name;
- Followers = new HashSet<string>();
- Following = new HashSet<string>();
- }
- public string Name { get; set; }
- public HashSet<string> Followers { get; set; }
- public HashSet<string> Following { get; set; }
- }
- }
Add Comment
Please, Sign In to add comment