static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List <Team> teams = new List <Team>(); for (int i = 0; i < n; i++) { string[] teamWithCreator = Console.ReadLine() .Split("-", StringSplitOptions.RemoveEmptyEntries) .ToArray(); Team team = new Team(teamWithCreator[1], teamWithCreator[0]); if ((teams.FirstOrDefault(x => x.TeamName.ToString() == teamWithCreator[1])) != null) { Console.WriteLine($"Team {teamWithCreator[1]} was already created!"); continue; } if ((teams.FirstOrDefault(x => x.Creator.ToString() == teamWithCreator[0])) != null) { Console.WriteLine($"{teamWithCreator[0]} cannot create another team!"); continue; } teams.Add(team); Console.WriteLine($"Team {teamWithCreator[1]} has been created by {teamWithCreator[0]}!"); } string command = Console.ReadLine(); while (command != "end of assignment") { string[] info = command.Split("->", StringSplitOptions.RemoveEmptyEntries).ToArray(); string newUser = info[0]; string teamName = info[1]; bool isTeamExist = teams.Select(x => x.TeamName).Contains(teamName); bool isCreatorExist = teams.Select(x => x.Creator).Contains(newUser); bool isMemberExist = teams.Select(x => x.Members) .Any(x => x.Contains(newUser)); if (!isTeamExist) { Console.WriteLine($"Team {teamName} does not exist!"); } else if (isCreatorExist || isMemberExist) { Console.WriteLine($"Member {newUser} cannot join team {teamName}!"); } else { int index = teams.FindIndex(x => x.TeamName == teamName); teams[index].Members.Add(newUser); } command = Console.ReadLine(); } Team[] teamsToDisband = teams.OrderBy(x => x.TeamName) .Where(x => x.Members.Count == 0).ToArray(); Team[] fullTeam = teams.OrderByDescending(x => x.Members.Count) .ThenBy(x => x.TeamName) .Where(x => x.Members.Count > 0) .ToArray(); StringBuilder strb = new StringBuilder(); foreach (Team item in fullTeam) { strb.AppendLine($"{item.TeamName}"); strb.AppendLine($"- {item.Creator}"); foreach (var something in item.Members.OrderBy(x => x)) { strb.AppendLine($"-- {something}"); } } strb.AppendLine("Teams to disband:"); foreach (var item in teamsToDisband) { strb.AppendLine(item.TeamName); } Console.WriteLine(strb); }
public static void Main() { int teamCount = int.Parse(Console.ReadLine()); List <Team> teams = new List <Team>(); for (int i = 0; i < teamCount; i++) { string[] splittedInput = Console.ReadLine().Split('-'); string creatorName = splittedInput[0]; string teamName = splittedInput[1]; bool isTeamNameExist = teams.Select(x => x.Name).Contains(teamName); //bool isTeamNameExist = teams.Any(x => x.Name == teamName); bool isCreatorNameExist = teams.Any(x => x.CreatorName == creatorName); if (isTeamNameExist == false && isCreatorNameExist == false) { Team team = new Team(teamName, creatorName); teams.Add(team); Console.WriteLine($"Team {teamName} has been created by {creatorName}!"); } else if (isTeamNameExist) { Console.WriteLine($"Team {teamName} was already created!"); } else if (isCreatorNameExist) { Console.WriteLine($"{creatorName} cannot create another team!"); } } while (true) { string input = Console.ReadLine(); if (input == "end of assignment") { break; } string[] splittedInput = input.Split("->"); string user = splittedInput[0]; string teamName = splittedInput[1]; bool isTeamExist = teams.Any(x => x.Name == teamName); bool isAlreadyMember = teams.Any(x => x.Members.Contains(user) || x.CreatorName == user); if (isTeamExist == false) { Console.WriteLine($"Team {teamName} does not exist!"); continue; } if (isAlreadyMember) { Console.WriteLine($"Member {user} cannot join team {teamName}!"); continue; } if (isTeamExist && isAlreadyMember == false) { int indexOfTeam = teams.FindIndex(x => x.Name == teamName); teams[indexOfTeam].Members.Add(user); } } List <Team> teamsWithMembers = teams .Where(x => x.Members.Count > 0) .OrderByDescending(x => x.Members.Count) .ThenBy(x => x.Name) .ToList(); List <Team> teamsWithoutMembers = teams .Where(x => x.Members.Count == 0) .OrderBy(x => x.Name) .ToList(); foreach (Team team in teamsWithMembers) { Console.WriteLine(team.Name); Console.WriteLine("- " + team.CreatorName); Console.WriteLine(string.Join(Environment.NewLine, team.Members.OrderBy(x => x).Select(x => $"-- {x}"))); } Console.WriteLine("Teams to disband:"); foreach (Team team in teamsWithoutMembers) { Console.WriteLine(team.Name); } }
static void Main(string[] args) { List <Team> teams = new List <Team>(); int numOfTeams = int.Parse(Console.ReadLine()); for (int i = 0; i < numOfTeams; i++) { var info = Console.ReadLine().Split("-").ToArray(); string creator = info[0]; string teamName = info[1]; // Create a team if (teams.Any(x => x.Name == teamName)) { Console.WriteLine($"Team {teamName} was already created!"); continue; } if (teams.Any(x => x.Creator == creator)) { Console.WriteLine($"{creator} cannot create another team!"); continue; } Team team = new Team(teamName, creator); teams.Add(team); Console.WriteLine($"Team {teamName} has been created by {creator}!"); } string command = String.Empty; while ((command = Console.ReadLine()) != "end of assignment") { var info = command.Split("->").ToArray(); string person = info[0]; string teamName = info[1]; if (!teams.Any(x => x.Name == teamName)) { Console.WriteLine($"Team {teamName} does not exist!"); continue; } if (teams.Any(x => x.peopleJoined.Contains(person)) || teams.Any(x => x.Creator == person && x.Name == teamName)) { Console.WriteLine($"Member {person} cannot join team {teamName}!"); continue; } int index = teams.FindIndex(x => x.Name == teamName); teams[index].peopleJoined.Add(person); } var teamsToBeDisbanded = teams .FindAll(x => x.peopleJoined.Count == 0) .OrderBy(x => x.Name) .ToList(); foreach (var team in teams.Where(x => x.peopleJoined.Count > 0) .OrderByDescending(x => x.peopleJoined.Count) .ThenBy(x => x.Name)) { Console.WriteLine(team.ToString()); } Console.WriteLine("Teams to disband:"); foreach (var team in teamsToBeDisbanded) { Console.WriteLine(team.Name); } }