static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            SortedList <string, Team> teams          = new SortedList <string, Team>();
            List <string>             admins         = new List <string>();
            List <string>             alreadymembers = new List <string>();
            List <string>             disband        = new List <string>();
            bool found = false;

            for (int i = 0; i < n; i++)
            {
                string[] teamAndCreator = Console.ReadLine().Split('-');
                Team     currTeam       = new Team();
                string   creator        = teamAndCreator[0];
                string   nameofTeam     = teamAndCreator[1];
                if (!teams.ContainsKey(nameofTeam))
                {
                    if (!admins.Contains(creator))
                    {
                        Console.WriteLine("Team " + nameofTeam + " has been created by " + creator + "!");
                        teams.Add(nameofTeam, new Team());
                        teams[nameofTeam].creator = creator;
                        admins.Add(creator);
                    }
                    else
                    {
                        Console.WriteLine(creator + " cannot create another team!");
                    }
                }
                else
                {
                    Console.WriteLine("Team " + nameofTeam + " was already created!");
                }
            }
            string[] assignment = Console.ReadLine().Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
            while (assignment[0] != "end of assignment")
            {
                string person      = assignment[0];
                string wantingTeam = assignment[1];


                if (teams.ContainsKey(wantingTeam))
                {
                    if (!alreadymembers.Contains(person) && !admins.Contains(person))
                    {
                        if (teams[wantingTeam].members == null)
                        {
                            teams[wantingTeam].members = new List <string>();
                        }
                        teams[wantingTeam].members.Add(person);
                        alreadymembers.Add(person);
                    }
                    else
                    {
                        Console.WriteLine("Member " + person + " cannot join team " + wantingTeam + "!");
                    }
                }
                else
                {
                    Console.WriteLine("Team " + wantingTeam + " does not exist!");
                }
                assignment = Console.ReadLine().Split(new char[] { '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
            }
            foreach (var item in teams.Where(x => x.Value.members != null).OrderByDescending(x => x.Value.members.Count).ThenBy(x => x.Key))
            {
                Console.WriteLine(item.Key);
                Console.WriteLine("- " + item.Value.creator);

                foreach (var member in item.Value.members.OrderBy(x => x))
                {
                    Console.WriteLine("-- " + member);
                }
            }


            Console.WriteLine("Teams to disband:");


            foreach (var team in teams.Where(x => x.Value.members == null).OrderBy(x => x.Key))
            {
                Console.WriteLine(team.Key);
            }
        }
        public static void Main()
        {
            var teamsLimit = int.Parse(Console.ReadLine());
            var command    = Console.ReadLine();
            var teamList   = new List <Team>();

            while (command != "end of assignment")
            {
                if (command.Contains("->"))
                {
                    var isUserInTeam = false;
                    var data         = command.Split("->");
                    var user         = data[0];
                    var teamName     = data[1];

                    foreach (var team in teamList.Where(x => x.User != null))
                    {
                        if (team.User.Contains(user))
                        {
                            isUserInTeam = true;
                            break;
                        }
                    }

                    if (isUserInTeam == true || teamList.Select(x => x.Creator).Contains(user))
                    {
                        Console.WriteLine($"Member {user} cannot join team {teamName}!");
                    }

                    else if (!teamList.Select(x => x.Name).Contains(teamName))
                    {
                        Console.WriteLine($"Team {teamName} does not exist!");
                    }

                    else
                    {
                        foreach (var team in teamList.Where(x => x.Name == teamName))
                        {
                            team.User += user + ",";
                        }
                    }
                }


                else
                {
                    var data     = command.Split("-");
                    var creator  = data[0];
                    var teamName = data[1];

                    if (teamList.Select(x => x.Name).Contains(teamName))
                    {
                        Console.WriteLine($"Team {teamName} was already created!");
                    }

                    else if (teamList.Select(x => x.Creator).Contains(creator))
                    {
                        Console.WriteLine($"{creator} cannot create another team!");
                    }


                    else
                    {
                        if (!teamList.Select(x => x.User).Contains(creator))
                        {
                            var projectTeam = new Team {
                                Name = teamName, Creator = creator
                            };
                            Console.WriteLine($"Team {teamName} has been created by {creator}!");
                            teamList.Add(projectTeam);
                        }
                    }
                }

                command = Console.ReadLine();
            }

            foreach (var team in teamList
                     .Where(x => x.User != null)
                     .OrderByDescending(x => x.User.Split(',').Count())
                     .ThenBy(x => x.Name))
            {
                var users = team.User.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();

                Console.WriteLine(team.Name);
                Console.WriteLine("- " + team.Creator);
                Console.WriteLine("-- " + string.Join(Environment.NewLine + "-- ", users.OrderBy(x => x)));
            }

            Console.WriteLine("Teams to disband:");
            foreach (var team in teamList.Where(x => x.User == null).OrderBy(x => x.Name))
            {
                Console.WriteLine(team.Name);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            int countTeams = int.Parse(Console.ReadLine());

            List <Team> teamsList = new List <Team>();

            for (int i = 0; i < countTeams; i++)
            {
                string[] info   = Console.ReadLine().Split("-").ToArray();
                string   person = info[0];
                string   team   = info[1];
                Team     teams  = new Team(person, team);
                if (!teamsList.Select(x => x.TeamName).Contains(team))
                {
                    if (!teamsList.Select(x => x.Creator).Contains(person))
                    {
                        teamsList.Add(teams);
                        Console.WriteLine($"Team {team} has been created by {person}!");
                    }
                    else
                    {
                        Console.WriteLine($"{person} cannot create another team!");
                    }
                }
                else
                {
                    Console.WriteLine($"Team {team} was already created!");
                }
            }
            string command = Console.ReadLine();

            while (command != "end of assignment")
            {
                string[] info   = command.Split("->").ToArray();
                string   person = info[0];
                string   team   = info[1];
                if (!teamsList.Select(x => x.TeamName).Contains(team))
                {
                    Console.WriteLine($"Team {team} does not exist!");
                }
                else if (teamsList.Select(x => x.Creator).Contains(person) || teamsList.Select(x => x.users).Any(x => x.Contains(person)))
                {
                    Console.WriteLine($"Member {person} cannot join team {team}!");
                }
                else
                {
                    int index = teamsList.FindIndex(x => x.TeamName == team);
                    teamsList[index].users.Add(person);
                }
                command = Console.ReadLine();
            }
            var disbanded = teamsList.OrderBy(x => x.TeamName).Where(x => x.users.Count == 0).ToList();
            var valid     = teamsList.OrderByDescending(x => x.users.Count).ThenBy(x => x.TeamName).Where(x => x.users.Count > 0).ToList();

            foreach (var item in valid)
            {
                Console.WriteLine(item.ToString());
            }
            Console.WriteLine($"Teams to disband:");
            foreach (var item in disbanded)
            {
                Console.WriteLine(item.TeamName);
            }
        }
        static void Main(string[] args)
        {
            int         countOfTeams   = int.Parse(Console.ReadLine());
            List <Team> teams          = new List <Team>();
            List <Team> disbandedTeams = new List <Team>();

            for (int i = 0; i < countOfTeams; i++)
            {
                string[] creatorAndTeamName = Console.ReadLine().Split("-");

                string creator  = creatorAndTeamName[0];
                string teamName = creatorAndTeamName[1];

                Team team = new Team()
                {
                    Creator = creator,
                    Name    = teamName,
                    Members = new List <string>()
                };

                if (IsCurrentTeamExisting(teams, teamName))
                {
                    Console.WriteLine($"Team {team.Name} was already created!");
                }
                else if (IsCreatorExisting(teams, creator))
                {
                    Console.WriteLine($"{team.Creator} cannot create another team!");
                }
                else
                {
                    teams.Add(team);
                    Console.WriteLine($"Team {team.Name} has been created by {team.Creator}!");
                }
            }

            string userNameAndTeamToJoin = Console.ReadLine();

            while (userNameAndTeamToJoin != "end of assignment")
            {
                string[] arr = userNameAndTeamToJoin.Split("->");

                string member     = arr[0];
                string teamToJoin = arr[1];

                Team currentTeam = teams.FirstOrDefault(t => t.Name == teamToJoin);

                if (currentTeam == null)
                {
                    Console.WriteLine($"Team {teamToJoin} does not exist!");
                }
                else if (CheckIfMemberIsCreator(teams, member))
                {
                    Console.WriteLine($"Member {member} cannot join team {teamToJoin}!");
                }
                else
                {
                    currentTeam.Members.Add(member);
                }

                userNameAndTeamToJoin = Console.ReadLine();
            }

            disbandedTeams.AddRange(teams.Where(t => !t.Members.Any()));

            teams.RemoveAll(x => !x.Members.Any());

            foreach (var team in teams.OrderByDescending(m => m.Members.Count).ThenBy(t => t.Name))
            {
                Console.WriteLine(team.Name);
                Console.WriteLine("- {0}", team.Creator);

                foreach (var member in team.Members.OrderBy(m => m))
                {
                    Console.WriteLine($"-- {member}");
                }
            }

            Console.WriteLine("Teams to disband:");

            foreach (var dibanded in disbandedTeams.OrderByDescending(d => d.Members.Count).ThenBy(t => t.Name))
            {
                Console.WriteLine(dibanded.Name);

                foreach (var member in dibanded.Members.OrderBy(m => m))
                {
                    Console.WriteLine($"-- {member}");
                }
            }
        }