static void Main(string[] args) { // TODO: work in progres..... HashSet <Vlogger> vloggerSet = new HashSet <Vlogger>(); bool hasNextCommand = true; while (hasNextCommand) { string[] command = Console.ReadLine().Split(); string commandName = command[0]; if (!commandName.ToLower().Equals(STATISTICS_COMMAND)) { commandName = command[1]; } switch (commandName.ToLower()) { case SAVE_VLOGGER_COMMAND: string vloggerName = command[0]; Vlogger vlogger = new Vlogger(vloggerName); vloggerSet.Add(vlogger); break; case FOLLOW_VLOGGER_COMMAND: string followerName = command[0]; string existingVloggerName = command[2]; bool doesFollowerExists = vloggerSet.Any(v => v.Name.Equals(followerName)); bool doesVloggerExists = vloggerSet.Any(v => v.Name.Equals(existingVloggerName)); if (doesFollowerExists && doesVloggerExists) { Vlogger follower = vloggerSet .Where(v => v.Name.Equals(followerName)) .FirstOrDefault(); Vlogger following = vloggerSet .Where(v => v.Name.Equals(existingVloggerName)) .FirstOrDefault(); following.addFollower(follower); follower.addFollowing(following); } break; case STATISTICS_COMMAND: var vloggersByFollowers = vloggerSet.OrderByDescending(v => v.Followers.Count); Console.WriteLine($"The V-Logger has a total of {vloggerSet.Count} vloggers in its logs."); int counter = 1; foreach (var v in vloggersByFollowers) { Console.WriteLine($"{counter}. {v.Name} : {v.Followers.Count} followers, {v.Following.Count} following"); if (v == vloggersByFollowers.First()) { foreach (var vloggerFollower in v.Followers) { Console.WriteLine($"* {vloggerFollower.Name}"); } } counter++; } hasNextCommand = false; break; } } }
static void Main(string[] args) { List <Vlogger> vloggers = new List <Vlogger>(); var entry = Console.ReadLine(); while (entry != "Statistics") { var tokens = entry.Split(); if (tokens[1] == "joined") { string vloggerName = tokens[0]; Vlogger vlogger = new Vlogger(vloggerName); if (vloggers.FirstOrDefault(x => x.Name == vlogger.Name) == null) { vloggers.Add(vlogger); } } else if (tokens[1] == "followed") { string follower = tokens[0]; string vloggerToFollow = tokens[2]; if (vloggers.FirstOrDefault(x => x.Name == follower) != null && vloggers.FirstOrDefault(x => x.Name == vloggerToFollow) != null && follower != vloggerToFollow) { var user = vloggers.Find(x => x.Name == follower); var vlogger = vloggers.Find(x => x.Name == vloggerToFollow); user.Following.Add(vlogger.Name); vlogger.Followers.Add(user.Name); } } entry = Console.ReadLine(); } Console.WriteLine($"The V-Logger has a total of {vloggers.Count} vloggers in its logs."); int index = 1; foreach (var vlogger in vloggers.OrderByDescending(x => x.Followers.Count).ThenBy(x => x.Following.Count)) { var name = vlogger.Name; var followers = vlogger.Followers; var following = vlogger.Following; if (index == 1) { Console.WriteLine($"{index++}. {name} : {followers.Count} followers, {following.Count} following"); foreach (var follower in followers.OrderBy(x => x)) { Console.WriteLine($"* {follower}"); } } else { Console.WriteLine($"{index++}. {name} : {followers.Count} followers, {following.Count} following"); } } }