Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int countOfTeams = int.Parse(Console.ReadLine());

            List <RegisterTeam> registerTeams = new List <RegisterTeam>();

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

                string userCreator = registedTeamInfo[0];
                string teamName    = registedTeamInfo[1];

                RegisterTeam currentRegisterTeam = new RegisterTeam(userCreator, teamName);

                currentRegisterTeam.PrintMessages(currentRegisterTeam, registerTeams);
            }

            List <Join> joins = new List <Join>();

            while (true)
            {
                string[] joinInfo = Console.ReadLine().Split("->");

                if (joinInfo[0] == "end of assignment")
                {
                    break;
                }

                string userToJoin = joinInfo[0];
                string teamJoin   = joinInfo[1];

                Join currentJoin = new Join(userToJoin, teamJoin);

                currentJoin.PrintMessages(currentJoin, registerTeams, joins);
            }

            PrintResult(registerTeams, joins);
        }
Ejemplo n.º 2
0
        public void PrintMessages(Join currentJoin, List <RegisterTeam> registerTeams, List <Join> joins)
        {
            bool anotherTeam   = false;
            bool isValid       = false;
            bool userTryToJoin = false;

            foreach (var registerTeam in registerTeams)
            {
                anotherTeam   = false;
                isValid       = false;
                userTryToJoin = false;

                if (registerTeam.TeamName.Contains(currentJoin.TeamJoin))
                {
                    if (registerTeam.UserCreator.Contains(currentJoin.UserToJoin))
                    {
                        // Member of a team cannot join another team - message should be thrown:

                        anotherTeam = true;
                    }
                    else
                    {
                        // if everything is OK

                        isValid = true;

                        break;
                    }
                }

                if (!registerTeam.UserCreator.Contains(currentJoin.UserToJoin))
                {
                    if (!registerTeam.TeamName.Contains(currentJoin.TeamJoin))
                    {
                        // If user tries to join currently non-existing team a message should be displayed:

                        userTryToJoin = true;
                    }
                    else
                    {
                        // if everything is OK

                        isValid = true;

                        break;
                    }
                }
            }

            if (isValid)
            {
                joins.Add(currentJoin);
            }
            else if (userTryToJoin)
            {
                Console.WriteLine($"Team {TeamJoin} does not exist!");
            }
            else if (anotherTeam)
            {
                Console.WriteLine($"Member {UserToJoin} cannot join team {TeamJoin}!");
            }
        }