示例#1
0
        static void Main(string[] args)
        {
            List <Team> teams = new List <Team>();

            int numberOfTeams = int.Parse(Console.ReadLine());


            for (int i = 0; i < numberOfTeams; i++)
            {
                var info = Console.ReadLine().Split("-").ToArray();

                string creator  = info[0];
                string teamName = info[1];
                //create team

                if (teams.Any(x => x.UserName == teamName))
                {
                    Console.WriteLine($"Team {teamName} was already created!");
                    continue;
                }
                else 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 userName = info[0];
                string teamName = info[1];
                //add person to team

                if (!teams.Any(x => x.UserName == teamName))
                {
                    Console.WriteLine($"Team {teamName} does not exist!");
                    continue;
                }
                if (teams.Any(x => x.PeopleJoint.Contains(userName) || teams.Any(x => x.Creator == userName && x.UserName == teamName)))
                {
                    Console.WriteLine($"Member {userName} cannot join team {teamName}!");
                    continue;
                }


                int index = teams.FindIndex(x => x.UserName == teamName);
                teams[index].PeopleJoint.Add(userName);
            }

            var teamsToBeDisbounded = teams
                                      .FindAll(x => x.PeopleJoint.Count == 0)
                                      .OrderBy(x => x.UserName)
                                      .ToList();

            foreach (var team in teams.Where(x => x.PeopleJoint.Count > 0)
                     .OrderByDescending(x => x.PeopleJoint.Count)
                     .ThenBy(x => x.UserName))
            {
                Console.WriteLine(team.ToString());
            }

            //var validTeams = teams.FindAll(x => x.PeopleJoint.Count > 0).OrderBy(x => x.UserName).ToList();

            //Console.WriteLine(string.Join(Environment.NewLine,validTeams
            //    .OrderByDescending(x => x.PeopleJoint.Count)
            //    .ThenBy(x => x.UserName)));

            Console.WriteLine("Teams to disband: ");
            foreach (var item in teamsToBeDisbounded)
            {
                Console.WriteLine(item.UserName);
            }
        }
        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);
            }
        }