Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Queue <Trainer> trainers = new Queue <Trainer>();

            string input;

            while ((input = Console.ReadLine()) != "Tournament")
            {
                string[] inputArgs = input
                                     .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                     .Select(x => x.Trim())
                                     .ToArray();

                string trainerName = inputArgs[0];
                string pokemonName = inputArgs[1];
                string element     = inputArgs[2];
                int    health      = int.Parse(inputArgs[3]);

                Pokemon pokemon = new Pokemon(pokemonName, element, health);

                var currentTrainer = trainers.Where(t => t.Name == trainerName).FirstOrDefault();

                if (currentTrainer == null)
                {
                    currentTrainer = new Trainer(trainerName);
                    currentTrainer.Pokemons.Push(pokemon);
                    trainers.Enqueue(currentTrainer);
                }

                else
                {
                    currentTrainer.Pokemons.Push(pokemon);
                }
            }

            string command;

            while ((command = Console.ReadLine().Trim()) != "End")
            {
                foreach (var trainer in trainers)
                {
                    if (trainer.Pokemons.Where(p => p.Element == command).FirstOrDefault() == null)
                    {
                        foreach (var pokemon in trainer.Pokemons)
                        {
                            pokemon.ReduceHealth();
                        }

                        trainer.RemovePokemon();
                    }

                    else
                    {
                        trainer.AddBages();
                    }
                }
            }


            Console.WriteLine(String.Join(Environment.NewLine, trainers
                                          .OrderByDescending(t => t.BagesCount)
                                          .Select(t => $"{t.Name} {t.BagesCount} {t.Pokemons.Count}")));
        }
Exemplo n.º 2
0
        public static void Main()
        {
            List <Trainer> trainers = new List <Trainer>();

            try
            {
                while (true)
                {
                    string input = Console.ReadLine();

                    if (input == "Tournament")
                    {
                        break;
                    }

                    string[] tokens = input
                                      .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                      .ToArray();

                    string trainerName    = tokens[0];
                    string pokemonName    = tokens[1];
                    string pokemonElement = tokens[2];
                    int    pokemonHealth  = int.Parse(tokens[3]);

                    Trainer currentTrainer = CreateTrainer(trainerName);
                    Pokemon currentPokemon = CreatePokemon(pokemonName, pokemonElement, pokemonHealth);

                    currentTrainer.Pokemons.Add(currentPokemon);

                    bool wasAdded = false;

                    foreach (Trainer trainer in trainers)
                    {
                        if (trainer.Name == trainerName)
                        {
                            trainer.Pokemons.Add(currentPokemon);
                            wasAdded = true;
                            break;
                        }
                    }

                    if (!wasAdded)
                    {
                        trainers.Add(currentTrainer);
                    }
                }

                while (true)
                {
                    string secondInput = Console.ReadLine();

                    if (secondInput == "End")
                    {
                        break;
                    }

                    for (int i = 0; i < trainers.Count; i++)
                    {
                        Trainer currentTrainer = trainers[i];

                        if (currentTrainer.ContainsType(secondInput))
                        {
                            currentTrainer.NumberOfBadges++;
                        }
                        else
                        {
                            currentTrainer.DecreaseHealth();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            trainers = trainers.OrderByDescending(t => t.NumberOfBadges).ToList();

            foreach (Trainer trainer in trainers)
            {
                Console.WriteLine(trainer.ToString().TrimEnd());
            }
        }