static void Main() { string[] input = Console.ReadLine().Split(" "); List <Vlogger> vLogger = new List <Vlogger>(); HashSet <string> existedVlogers = new HashSet <string>(); while (input[0] != "Statistics") { if (input[1] == "joined") { if (!existedVlogers.Contains(input[0])) // doesn't exist { Vlogger currentVloger = new Vlogger(); currentVloger.Name = input[0]; currentVloger.Followers = new List <string>(); currentVloger.Following = new List <string>(); vLogger.Add(currentVloger); existedVlogers.Add(input[0]); } } else if (input[1] == "followed") { if ((input[0] != input[2]) && (existedVlogers.Contains(input[0]) && existedVlogers.Contains(input[2]))) { // Vlogger currentVloger = new Vlogger(); int index = FindVloger(vLogger, input[2]); if (!vLogger[index].Followers.Contains(input[0])) { vLogger[index].Followers.Add(input[0]); index = FindVloger(vLogger, input[0]); vLogger[index].Following.Add(input[2]); } } } input = Console.ReadLine().Split(" "); } vLogger = vLogger.OrderByDescending(x => x.Followers.Count).ThenBy(x => x.Following.Count).ToList(); Console.WriteLine($"The V-Logger has a total of {vLogger.Count} vloggers in its logs."); Console.WriteLine($"1. {vLogger[0].Name} : {vLogger[0].Followers.Count} followers, " + $"{vLogger[0].Following.Count} following"); vLogger[0].Followers.Sort(); for (int i = 0; i < vLogger[0].Followers.Count; i++) { Console.WriteLine($"* {vLogger[0].Followers[i]}"); } for (int i = 1; i < vLogger.Count; i++) { Console.WriteLine($"{i+1}. {vLogger[i].Name} : {vLogger[i].Followers.Count} followers, " + $"{vLogger[i].Following.Count} following"); } }
static void Main() { List <Vlogger> records = new List <Vlogger>(); string inputCommand = Console.ReadLine(); while (inputCommand != "Statistics") { string[] commandInfo = inputCommand .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); if (commandInfo.Length == 4) { string vloggerName = commandInfo[0]; if (!records.Any(x => x.Name == vloggerName)) { Vlogger user = new Vlogger(vloggerName); records.Add(user); } } else { string followerName = commandInfo[0]; string followingName = commandInfo[2]; var follower = records.FirstOrDefault(x => x.Name == followerName); var following = records.FirstOrDefault(x => x.Name == followingName); if (follower != null && following != null && follower != following) { follower.Following.Add(followingName); following.Followers.Add(followerName); } } inputCommand = Console.ReadLine(); } Console.WriteLine($"The V-Logger has a total of {records.Count} vloggers in its logs."); PrintVloggers(records); }
static void Main() { Dictionary <string, Vlogger> vloggers = new Dictionary <string, Vlogger>(); string input = Console.ReadLine(); while (input != "Statistics") { string[] tokens = input.Split(); string vloggerName = tokens[0]; string command = tokens[1]; if (command == "joined") { if (!vloggers.ContainsKey(vloggerName)) { Vlogger vlogger = new Vlogger(vloggerName); vloggers.Add(vloggerName, vlogger); } } else { string vloggerFollowerName = tokens[2]; if (vloggers.ContainsKey(vloggerName) && vloggers.ContainsKey(vloggerFollowerName) && vloggerName != vloggerFollowerName) { vloggers[vloggerName].Following.Add(vloggerFollowerName); vloggers[vloggerFollowerName].Followers.Add(vloggerName); } } input = Console.ReadLine(); } Console.WriteLine($"The V-Logger has a total of {vloggers.Count} vloggers in its logs."); int count = 1; foreach (var item in vloggers.OrderByDescending(v => v.Value.Followers.Count).ThenBy(v => v.Value.Following.Count)) { Console.WriteLine($"{count}. {item.Key} : {item.Value.Followers.Count} followers, {item.Value.Following.Count} following"); if (count == 1) { foreach (var follower in item.Value.Followers.OrderBy(n => n)) { Console.WriteLine($"* {follower}"); } } count++; } }