Пример #1
0
        public static void Main(string[] args)
        {
            var inp       = Console.ReadLine();
            var container = new List <Trainer>();

            while (inp.ToLower() != "tournament")
            {
                var line = inp.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                var pokemon = new Pokemon(line[1], line[2], int.Parse(line[3]));

                var trainer = new Trainer(line[0]);

                var count = 0;

                foreach (var li in container)
                {
                    if (li.TrainerName == line[0])
                    {
                        li.listPokemon.Add(pokemon);
                        count++;
                        break;
                    }
                }
                if (count == 0)
                {
                    trainer.listPokemon.Add(pokemon);
                    container.Add(trainer);
                }

                inp = Console.ReadLine();
            }

            var cmd = Console.ReadLine();

            while (cmd.ToLower() != "end")
            {
                foreach (var trainer in container)
                {
                    var count = 0;

                    foreach (var li in trainer.listPokemon)
                    {
                        if (li.Element == cmd)
                        {
                            count++;
                        }
                    }
                    if (count > 0)
                    {
                        trainer.Badges++;
                    }
                    else
                    {
                        foreach (var li in trainer.listPokemon)
                        {
                            li.Health -= 10;
                        }
                    }

                    var removePokemon = new List <Pokemon>();
                    foreach (var pokemon in trainer.listPokemon)
                    {
                        if (pokemon.Health <= 0)
                        {
                            removePokemon.Add(pokemon);
                        }
                    }
                    foreach (var item in removePokemon)
                    {
                        trainer.listPokemon.Remove(item);
                    }
                }
                cmd = Console.ReadLine();
            }



            foreach (var li in container.OrderByDescending(x => x.Badges))
            {
                Console.WriteLine(li.TrainerName + " " + li.Badges + " " + li.listPokemon.Count);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Dictionary <string, Trainer> trainers = new Dictionary <string, Trainer>();

            string[] info = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

            while (info[0] != "Tournament")
            {
                string trainerName    = info[0];
                string pokemonName    = info[1];
                string pokemonElement = info[2];
                int    pokemonHealth  = int.Parse(info[3]);

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                if (!trainers.ContainsKey(trainerName))
                {
                    Trainer trainer = new Trainer(trainerName);
                    trainer.Pokemons.Add(pokemon);
                    trainers.Add(trainerName, trainer);
                }
                else
                {
                    trainers[trainerName].Pokemons.Add(pokemon);
                }

                info = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            }

            string elementToFind = Console.ReadLine();

            while (elementToFind != "End")
            {
                foreach (var currenttrainer in trainers)
                {
                    bool elementFound = false;

                    for (int i = 0; i < currenttrainer.Value.Pokemons.Count; i++)
                    {
                        if (currenttrainer.Value.Pokemons[i].Element == elementToFind)
                        {
                            currenttrainer.Value.Badges++;
                            elementFound = true;
                            break;
                        }
                    }

                    if (!elementFound)
                    {
                        for (int i = 0; i < currenttrainer.Value.Pokemons.Count; i++)
                        {
                            currenttrainer.Value.Pokemons[i].Health -= 10;

                            if (currenttrainer.Value.Pokemons[i].Health <= 0)
                            {
                                currenttrainer.Value.Pokemons.Remove(currenttrainer.Value.Pokemons[i]);
                            }
                        }
                    }
                }

                elementToFind = Console.ReadLine();
            }

            foreach (var currentTrainer in trainers.OrderByDescending(x => x.Value.Badges))
            {
                Console.WriteLine($"{currentTrainer.Key} {currentTrainer.Value.Badges} {currentTrainer.Value.Pokemons.Count}");
            }
        }
Пример #3
0
        static void IsItHave(List <Trainer> currentTrainer, string command)
        {
            bool flag = false;

            if (command == "Fire")
            {
                foreach (var items in currentTrainer)
                {
                    foreach (var itens in items.Pokemon)
                    {
                        if (itens.Element == "Fire")
                        {
                            Trainer trainer = items;

                            flag = true;
                            trainer.NumberOfBadje++;
                            break;
                        }
                    }

                    if (flag)
                    {
                        flag = false;
                        continue;
                    }
                    else
                    {
                        for (int i = 0; i < items.Pokemon.Count; i++)
                        {
                            Trainer trainer        = items;
                            Pokemon currentPokemon = items.Pokemon[i];
                            currentPokemon.Health -= 10;

                            if (currentPokemon.Health <= 0)
                            {
                                trainer.Pokemon.Remove(currentPokemon);
                            }
                        }
                    }
                }
            }
            else if (command == "Water")
            {
                foreach (var items in currentTrainer)
                {
                    foreach (var itens in items.Pokemon)
                    {
                        if (itens.Element == "Water")
                        {
                            Trainer trainer = items;

                            flag = true;
                            trainer.NumberOfBadje++;
                            break;
                        }
                    }

                    if (flag)
                    {
                        flag = false;
                        continue;
                    }
                    else
                    {
                        for (int i = 0; i < items.Pokemon.Count; i++)
                        {
                            Trainer trainer        = items;
                            Pokemon currentPokemon = items.Pokemon[i];
                            currentPokemon.Health -= 10;

                            if (currentPokemon.Health <= 0)
                            {
                                trainer.Pokemon.Remove(currentPokemon);
                            }
                        }
                    }
                }
            }
            else if (command == "Electricity")
            {
                foreach (var items in currentTrainer)
                {
                    foreach (var itens in items.Pokemon)
                    {
                        if (itens.Element == "Electricity")
                        {
                            Trainer trainer = items;

                            flag = true;
                            trainer.NumberOfBadje++;
                            break;
                        }
                    }

                    if (flag)
                    {
                        flag = false;
                        continue;
                    }
                    else
                    {
                        for (int i = 0; i < items.Pokemon.Count; i++)
                        {
                            Trainer trainer        = items;
                            Pokemon currentPokemon = items.Pokemon[i];
                            currentPokemon.Health -= 10;

                            if (currentPokemon.Health <= 0)
                            {
                                trainer.Pokemon.Remove(currentPokemon);
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            Dictionary <string, Trainer> trainers = new Dictionary <string, Trainer>();

            string input = Console.ReadLine();

            while (input != "Tournament")
            {
                string[] tokens = input.Split();

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

                Pokemon pokemon = new Pokemon(pokemonName, pokemonType, pokemonHealth);
                Trainer trainer = new Trainer(trainerName);
                trainer.Pokemons.Add(pokemon);

                if (!trainers.ContainsKey(trainerName))
                {
                    trainers.Add(trainerName, trainer);
                }
                else
                {
                    trainers[trainerName].Pokemons.Add(pokemon);
                }
                input = Console.ReadLine();
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                if (command == "Fire")
                {
                    foreach (var trainer in trainers)
                    {
                        if (trainer.Value.Pokemons.Any(p => p.Type == "Fire"))
                        {
                            trainer.Value.BadgesCount++;
                        }
                        else
                        {
                            trainer.Value.Pokemons.ForEach(x => x.Health -= 10);
                        }
                    }
                }

                else if (command == "Electricity")
                {
                    foreach (var trainer in trainers)
                    {
                        if (trainer.Value.Pokemons.Any(p => p.Type == "Electricity"))
                        {
                            trainer.Value.BadgesCount++;
                        }
                        else
                        {
                            trainer.Value.Pokemons.ForEach(x => x.Health -= 10);
                        }
                    }
                }
                else if (command == "Water")
                {
                    foreach (var trainer in trainers)
                    {
                        if (trainer.Value.Pokemons.Any(p => p.Type == "Water"))
                        {
                            trainer.Value.BadgesCount++;
                        }
                        else
                        {
                            trainer.Value.Pokemons.ForEach(x => x.Health -= 10);
                        }
                    }
                }
                command = Console.ReadLine();
            }

            foreach (var t in trainers)
            {
                t.Value.Pokemons.RemoveAll(x => x.Health <= 0);
            }

            foreach (var trainer in trainers.OrderByDescending(x => x.Value.BadgesCount))
            {
                Console.WriteLine($"{trainer.Value.Name} {trainer.Value.BadgesCount} {trainer.Value.Pokemons.Count}");
            }
        }
Пример #5
0
        public static void Main(string[] args)
        {
            Dictionary <string, Trainer> trainers = new Dictionary <string, Trainer>();

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

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

                string[] info = command.Split();

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

                if (!trainers.ContainsKey(trainerName))
                {
                    trainers.Add(trainerName, new Trainer(trainerName));
                }

                Trainer currentTrainer = trainers[trainerName];
                Pokemon pokemon        = new Pokemon(pokemonName, pokemonElement, pokemonHealt);

                currentTrainer.Pokemon.Add(pokemon);
            }

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

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

                foreach (var currentTrainer in trainers)
                {
                    if (currentTrainer.Value.Pokemon
                        .Any(p => p.Element == command))
                    {
                        currentTrainer.Value.NumberOfBadges++;
                    }
                    else
                    {
                        foreach (var pokemon in currentTrainer.Value.Pokemon)
                        {
                            pokemon.Health -= 10;
                        }

                        currentTrainer.Value.Pokemon.RemoveAll(p => p.Health <= 0);
                    }
                }
            }
            foreach (Trainer trainer in trainers.Values.OrderByDescending(t => t.NumberOfBadges))
            {
                Console.WriteLine(trainer);
            }
        }
Пример #6
0
        public static void Main(string[] args)
        {
            Dictionary <string, Trainer> trainers = new Dictionary <string, Trainer>();

            string input = Console.ReadLine();

            while (input != "Tournament")
            {
                //“<TrainerName> <PokemonName> <PokemonElement> <PokemonHealth>
                string[] tokens = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);

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

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                Trainer trainer = new Trainer()
                {
                    Name     = trainerName,
                    Badges   = 0,
                    Pokemons = new List <Pokemon>()
                };

                if (!trainers.ContainsKey(trainerName))
                {
                    trainers[trainerName] = trainer;
                    trainers[trainerName].Pokemons.Add(pokemon);
                }
                else
                {
                    trainers[trainerName].Pokemons.Add(pokemon);
                }

                input = Console.ReadLine();
            }

            string element = Console.ReadLine();

            while (element != "End")
            {
                foreach (var trainer in trainers.Values)
                {
                    foreach (var pokemon in trainer.Pokemons)
                    {
                        if (pokemon.Element == element)
                        {
                            trainer.Badges++;
                            break;
                        }
                        else
                        {
                            pokemon.Health -= 10;
                            if (pokemon.Health <= 0)
                            {
                                trainer.Pokemons.Remove(pokemon);
                                break;
                            }
                        }
                    }
                }
                element = Console.ReadLine();
            }

            foreach (var item in trainers.OrderByDescending(x => x.Value.Badges))
            {
                Console.WriteLine($"{item.Key} {item.Value.Badges} {item.Value.Pokemons.Count}");
            }
        }
        public static void Main(string[] args)
        {
            List<Trainer> trainers = new List<Trainer>();

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "Tournament")
            {
                string[] elements = input
                    .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                    .ToArray();

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

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                Trainer trainer = null;

                bool isTrainerAdded = trainers.Any(x => x.Name == trainerName);
                if (isTrainerAdded)
                {
                    trainer = trainers
                        .Where(x => x.Name == trainerName)
                        .FirstOrDefault();

                    trainer.Pokemons.Add(pokemon);
                }
                else
                {
                    trainer = new Trainer(trainerName);
                    trainer.Pokemons.Add(pokemon);

                    trainers.Add(trainer);
                }
            }

            while ((input = Console.ReadLine()) != "End")
            {
                string currentElement = input;

                foreach (Trainer trainer in trainers)
                {
                    bool isFound = trainer.Pokemons.Any(x => x.Element == currentElement);
                    if (isFound)
                    {
                        trainer.BadgesCount++;
                    }
                    else
                    {
                        foreach (Pokemon pokemon in trainer.Pokemons)
                        {
                            pokemon.Health -= 10;
                        }

                        trainer.Pokemons.RemoveAll(x => x.Health <= 0);
                    }
                }
            }

            trainers = trainers
                .OrderByDescending(x => x.BadgesCount)
                .ToList();

            foreach (Trainer trainer in trainers)
            {
                Console.WriteLine(trainer.ToString());
            }
        }
Пример #8
0
        public static void Main()
        {
            string input = Console.ReadLine();

            var     trainers = new List <Trainer>();
            Trainer trainer  = new Trainer();

            while (input != "Tournament")
            {
                var tokens = input
                             .Split(' ', StringSplitOptions.RemoveEmptyEntries);

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

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                Trainer currentTrainer = trainers.FirstOrDefault(x => x.Name == trainerName);

                if (currentTrainer != null)
                {
                    currentTrainer.PokemonCollection.Add(pokemon);
                    input = Console.ReadLine();
                    continue;
                }

                trainer      = new Trainer();
                trainer.Name = trainerName;
                trainer.PokemonCollection.Add(pokemon);
                trainers.Add(trainer);

                input = Console.ReadLine();
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                if (command == "Fire")
                {
                    CheckForMatch(trainers, command);
                }

                else if (command == "Water")
                {
                    CheckForMatch(trainers, command);
                }

                else if (command == "Electricity")
                {
                    CheckForMatch(trainers, command);
                }

                command = Console.ReadLine();
            }

            foreach (var pokemonTrainer in trainers.OrderByDescending(p => p.Badges))
            {
                Console.WriteLine($"{pokemonTrainer.Name} {pokemonTrainer.Badges} {pokemonTrainer.PokemonCollection.Count}");
            }
        }
        static void Main(string[] args)
        {
            string         input    = Console.ReadLine();
            List <Trainer> trainers = new List <Trainer>();

            while (input.ToLower() != "tournament")
            {
                string[] playerInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string name    = playerInfo[0];
                string pokemon = playerInfo[1];
                string element = playerInfo[2];
                int    health  = int.Parse(playerInfo[3]);

                var newPokemon = new Pokemon(pokemon, element, health);

                if (!ContainsTrainer(trainers, name))
                {
                    var list = new List <Pokemon>();
                    list.Add(newPokemon);

                    Trainer trainer = new Trainer(name, 0, list);
                    trainers.Add(trainer);
                }
                else
                {
                    // Trainer foundTrainer =
                    FindTrainer(trainers, name).Collection.Add(newPokemon);
                    //foundTrainer.Collection.Add(newPokemon);
                }
                input = Console.ReadLine();
            }

            string command = Console.ReadLine();

            while (command.ToLower() != "end")
            {
                for (int i = 0; i < trainers.Count; i++)
                {
                    Trainer currentTrainer = trainers[i];
                    bool    b = false;
                    foreach (var pokemon in currentTrainer.Collection)
                    {
                        if (pokemon.Element == command)
                        {
                            b = true;
                        }
                    }
                    if (b == true)
                    {
                        currentTrainer.Badges++;
                    }
                    else
                    {
                        for (int j = 0; j < currentTrainer.Collection.Count; j++)
                        {
                            Pokemon currentPokemon = currentTrainer.Collection[j];
                            currentPokemon.Health -= 10;

                            if (currentPokemon.Health <= 0)
                            {
                                currentTrainer.Collection.Remove(currentPokemon);
                            }
                        }
                    }
                }
                command = Console.ReadLine();
            }

            foreach (var player in trainers.OrderByDescending(x => x.Badges))
            {
                Console.WriteLine($"{player.Name} {player.Badges} {player.Collection.Count}");
            }
        }
Пример #10
0
        static void Main(string[] args)
        {
            var    trainers = new List <Trainer>();
            string command  = string.Empty;

            while ((command = Console.ReadLine()) != "Tournament")
            {
                var    info        = command.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                string trainerName = info[0];
                string pokemonName = info[1];
                string element     = info[2];
                int    health      = int.Parse(info[3]);

                if (!trainers.Any(t => t.Name == trainerName))
                {
                    var trainer = new Trainer(trainerName);
                    trainers.Add(trainer);
                }

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

                if (!currentTrainer.Pokemons.Any(p => p.Name == pokemonName))
                {
                    var pokemon = new Pokemon(pokemonName, element, health);
                    currentTrainer.Pokemons.Add(pokemon);
                }
                else
                {
                    currentTrainer.Pokemons.FirstOrDefault(p => p.Name == pokemonName).Element = element;
                    currentTrainer.Pokemons.FirstOrDefault(p => p.Name == pokemonName).Health += health;
                }
            }

            string elementInput = string.Empty;

            while ((elementInput = Console.ReadLine()) != "End")
            {
                for (int i = 0; i < trainers.Count; i++)
                {
                    var currentTrainer = trainers[i];

                    if (currentTrainer.Pokemons.Any(p => p.Element.Equals(elementInput)))
                    {
                        currentTrainer.Badges++;
                    }
                    else
                    {
                        currentTrainer.Pokemons.ForEach(p => p.Health -= 10);
                        for (int j = 0; j < currentTrainer.Pokemons.Count; j++)
                        {
                            if (currentTrainer.Pokemons[j].Health <= 0)
                            {
                                currentTrainer.Pokemons.RemoveAt(j);
                                j--;
                            }
                        }
                    }
                }
            }

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

            foreach (var trainer in trainers)
            {
                Console.WriteLine($"{trainer.Name} {trainer.Badges} {trainer.Pokemons.Count}");
            }
        }
Пример #11
0
        static void Main(string[] args)
        {
            List <Pokemon> pokemons = new List <Pokemon>();
            List <Trainer> trainers = new List <Trainer>();

            string input = Console.ReadLine();

            while (input != "Tournament")
            {
                string[] splittedInput = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);

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

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);


                Trainer trainer = new Trainer(trainerName, 0, new List <Pokemon>());

                bool HasTrainer = false;

                foreach (Trainer item in trainers)
                {
                    if (item.Name == trainerName)
                    {
                        item.Pokemons.Add(pokemon);
                        HasTrainer = true;
                    }
                }
                if (!HasTrainer)
                {
                    trainer.Pokemons.Add(pokemon);
                    trainers.Add(trainer);
                }


                input = Console.ReadLine();
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                bool hasElement = false;
                foreach (Trainer trainer in trainers)
                {
                    List <Pokemon> newList = new List <Pokemon>();
                    foreach (var item in trainer.Pokemons)
                    {
                        newList.Add(item);
                    }
                    foreach (var item in trainer.Pokemons)
                    {
                        if (item.Element == command)
                        {
                            trainer.Badges++;
                            hasElement = true;
                        }
                    }
                    if (!hasElement)
                    {
                        foreach (var item in trainer.Pokemons)
                        {
                            item.Health -= 10;
                            if (item.Health <= 0)
                            {
                                newList.Remove(item);
                            }
                        }
                    }
                    trainer.Pokemons = newList;
                }

                command = Console.ReadLine();
            }

            foreach (Trainer trainer in trainers.OrderByDescending(x => x.Badges))
            {
                Console.WriteLine($"{trainer.Name} {trainer.Badges} {trainer.Pokemons.Count}");
            }
        }
Пример #12
0
        static void Main(string[] args)
        {
            string cmd = string.Empty;


            List <Trainer> trainers = new List <Trainer>();
            List <Pokemon> pokemons = new List <Pokemon>();

            while ((cmd = Console.ReadLine()) != "Tournament")
            {
                string[] splitted = cmd
                                    .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                    .ToArray();

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

                Pokemon pokemon = new Pokemon
                                      (pokemonName, pokemonElement, pokemonHealth);

                bool isTrainerExist = trainers.Any(x => x.Name == trainerName);

                if (isTrainerExist)
                {
                    int index = trainers.FindIndex(x => x.Name == trainerName);
                    trainers[index].Pokemons.Add(pokemon);
                }
                else
                {
                    Trainer trainer = new Trainer(trainerName);
                    trainer.Pokemons.Add(pokemon);
                    trainers.Add(trainer);
                }

                pokemons.Add(pokemon);
            }
            string command = string.Empty;

            while ((command = Console.ReadLine()) != "End")
            {
                foreach (var item in trainers)
                {
                    if (item.Pokemons.Any(x => x.Element == command))
                    {
                        item.NumberOfBadges++;
                    }
                    else
                    {
                        foreach (var pokemon in item.Pokemons)
                        {
                            pokemon.Health -= 10;
                        }
                    }
                    HealthCheck(item);
                }
            }

            foreach (var item in trainers.OrderByDescending(x => x.NumberOfBadges))
            {
                Console.WriteLine($"{item.Name} {item.NumberOfBadges} {item.Pokemons.Count}");
            }
        }
        public static void Main()
        {
            Dictionary <string, Trainer> trainers = new Dictionary <string, Trainer>();

            string command = Console.ReadLine();

            while (command != "Tournament")
            {
                string[] commandInfo = command.Split(" ").ToArray();

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

                if (!trainers.ContainsKey(trainerName))
                {
                    trainers.Add(trainerName, new Trainer(trainerName));
                }

                Trainer trainer = trainers[trainerName];

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                trainer.Pokemons.Add(pokemon);

                command = Console.ReadLine();
            }

            command = Console.ReadLine();

            while (command != "End")
            {
                string element = command;

                foreach (var trainer in trainers)
                {
                    if (trainer.Value.Pokemons.Any(p => p.Element == element))
                    {
                        trainer.Value.Badges++;
                    }
                    else
                    {
                        foreach (var pokemon in trainer.Value.Pokemons)
                        {
                            pokemon.Health -= 10;
                        }
                        trainer.Value.Pokemons.RemoveAll(x => x.Health <= 0);
                    }
                }

                command = Console.ReadLine();
            }

            var result = trainers.OrderByDescending(x => x.Value.Badges)
                         .ToDictionary(k => k.Key, v => v.Value);

            foreach (var item in result)
            {
                Console.WriteLine($"{item.Key} {item.Value.Badges} {item.Value.Pokemons.Count}");
            }
        }
Пример #14
0
        static void Main(string[] args)
        {
            List <Trainer> trainers = new List <Trainer>();


            while (true)
            {
                string input = Console.ReadLine();
                if (input == "Tournament")
                {
                    break;
                }
                string[] info = input.Split();
                //< TrainerName > < PokemonName > < PokemonElement > < PokemonHealth >
                string trainerName    = info[0];
                string pokemonName    = info[1];
                string pokemonElement = info[2];
                int    pokemonHealth  = int.Parse(info[3]);

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                if (trainers.Exists(x => x.Name == trainerName))
                {
                    trainers.Find(x => x.Name == trainerName).Pokemons.Add(pokemon);
                }
                else
                {
                    Trainer trainer = new Trainer(trainerName);
                    trainer.Pokemons.Add(pokemon);

                    trainers.Add(trainer);
                }
            }

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

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

                foreach (Trainer trainer in trainers)
                {
                    if (trainer.Pokemons.Exists(x => x.Element == element))
                    {
                        trainer.BadgesCount += 1;
                    }
                    else
                    {
                        foreach (Pokemon pokemon in trainer.Pokemons)
                        {
                            pokemon.Health -= 10;
                        }

                        trainer.Pokemons.RemoveAll(x => x.Health <= 0);
                    }
                }
            }

            foreach (Trainer trainer in trainers.OrderByDescending(x => x.BadgesCount))
            {
                Console.WriteLine($"{trainer.Name} {trainer.BadgesCount} {trainer.Pokemons.Count}");
            }

            Console.ReadLine();
        }
Пример #15
0
        public static void Main(string[] args)
        {
            var trainersList = new List <Trainer>();


            string input = Console.ReadLine();

            while (input != "Tournament")
            {
                var    pokemonInfo    = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
                string trainerName    = pokemonInfo[0];
                string pokemonName    = pokemonInfo[1];
                string pokemonElement = pokemonInfo[2];
                int    pokemonHealth  = int.Parse(pokemonInfo[3]);

                Pokemon currentPokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);


                Trainer currentTrainer = trainersList.FirstOrDefault(x => x.Name == trainerName);

                if (currentTrainer == null)
                {
                    currentTrainer = new Trainer(trainerName);
                    trainersList.Add(currentTrainer);
                }

                currentTrainer.PokemonCollection.Add(currentPokemon);

                input = Console.ReadLine();
            }

            input = Console.ReadLine();

            while (input != "End")
            {
                foreach (var trainer in trainersList)
                {
                    if (trainer.PokemonCollection.Any(x => x.Element == input))
                    {
                        trainer.NumberOfBadges += 1;
                    }
                    else
                    {
                        foreach (var pokemon in trainer.PokemonCollection)
                        {
                            pokemon.Helath -= 10;
                        }
                    }
                }

                foreach (var trainer in trainersList)
                {
                    trainer.PokemonCollection.RemoveAll(x => x.Helath <= 0);
                }

                input = Console.ReadLine();
            }

            foreach (var trainer in trainersList.OrderByDescending(x => x.NumberOfBadges))
            {
                Console.WriteLine($"{trainer.Name} {trainer.NumberOfBadges} {trainer.PokemonCollection.Count}");
            }
        }
Пример #16
0
        static void Main(string[] args)
        {
            List <Trainer> trainers = new List <Trainer>();


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

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

                string[] inputData = line.Split().ToArray();

                Pokemon pokemon = new Pokemon(inputData[1], inputData[2], int.Parse(inputData[3]));

                if (!trainers.Any(t => t.Name == inputData[0]))
                {
                    Trainer trainer = new Trainer(inputData[0]);
                    trainers.Add(trainer);
                    trainer.Pokemons.Add(pokemon);
                }
                else
                {
                    var addedTrainer = trainers.Find(t => t.Name == inputData[0]);
                    addedTrainer.Pokemons.Add(pokemon);
                }
            }

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

                if (command == "End")
                {
                    break;
                }
                foreach (var trainer in trainers)
                {
                    if (trainer.Pokemons.Any(p => p.Element == command))
                    {
                        trainer.NumberOfBadges++;
                    }
                    else
                    {
                        for (int i = 0; i < trainer.Pokemons.Count; i++)
                        {
                            trainer.Pokemons[i].Health -= 10;
                            if (trainer.Pokemons[i].Health <= 0)
                            {
                                trainer.Pokemons.Remove(trainer.Pokemons[i]);
                                i--;
                            }
                        }
                    }
                }
            }

            foreach (var trainer in trainers.OrderByDescending(t => t.NumberOfBadges))
            {
                Console.WriteLine($"{trainer.Name} {trainer.NumberOfBadges} {trainer.Pokemons.Count}");
            }
        }
Пример #17
0
        public static void Main(string[] args)
        {
            List <Trainer> alltrainers  = new List <Trainer>();
            List <string>  trainerNames = new List <string>();

            while (true)
            {
                string[] trainerAndPokemonInfo = Console.ReadLine()
                                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                if (trainerAndPokemonInfo[0] == "Tournament")
                {
                    break;
                }
                if (trainerAndPokemonInfo.Length != 4)
                {
                    continue;
                }

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

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                if (!trainerNames.Contains(trainerName))
                {
                    trainerNames.Add(trainerName);
                    Trainer trainer = new Trainer(trainerName, pokemon);
                    alltrainers.Add(trainer);
                }
                else if (trainerNames.Contains(trainerName))
                {
                    Trainer trainerToAddPokemonTo = alltrainers.Where(x => x.TrainerName == trainerName).ToList()[0];
                    trainerToAddPokemonTo.PokemonCollection.Add(pokemon);
                }
            }

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

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

                foreach (var trainer in alltrainers)
                {
                    int countPokemonWithGivenElement = 0;

                    foreach (var pokemon in trainer.PokemonCollection)
                    {
                        if (pokemon.Element.Contains(command))
                        {
                            trainer.NumberOfBadges += 1;
                            countPokemonWithGivenElement++;

                            break;
                        }
                    }
                    if (countPokemonWithGivenElement == 0)
                    {
                        foreach (var currentPokemon in trainer.PokemonCollection.ToList())
                        {
                            currentPokemon.Health -= 10;
                            if (currentPokemon.Health <= 0)
                            {
                                trainer.PokemonCollection.Remove(currentPokemon);
                            }
                        }
                    }
                }
            }
            foreach (var trainer in alltrainers.OrderByDescending(x => x.NumberOfBadges))
            {
                Console.WriteLine($"{trainer.TrainerName} {trainer.NumberOfBadges} {trainer.PokemonCollection.Where(x => x.Health > 0).Count()}");
            }
        }
Пример #18
0
        static void Main()
        {
            List <Trainer> trainers = new List <Trainer>();

            string inputTrainers;

            while ((inputTrainers = Console.ReadLine()) != "Tournament")
            {
                string[] info           = inputTrainers.Split(" ").ToArray();
                string   name           = info[0];
                string   pokemonName    = info[1];
                string   pokemonElement = info[2];
                int      pokemonHealth  = int.Parse(info[3]);


                if (!trainers.Any(t => t.Name == name))
                {
                    List <Pokemon> pokemons = new List <Pokemon>();
                    Pokemon        pokemon  = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                    pokemons.Add(pokemon);
                    int     badges  = 0;
                    Trainer trainer = new Trainer(name, badges, pokemons);
                    trainers.Add(trainer);
                }
                else
                {
                    if (trainers.Any(t => t.Name == name))
                    {
                        Trainer currentTrainer = trainers.FirstOrDefault(t => t.Name == name);
                        Pokemon pokemon        = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                        currentTrainer.Pokemons.Add(pokemon);
                    }
                }
            }

            Console.WriteLine();

            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                foreach (Trainer trainer in trainers)
                {
                    if (trainer.Pokemons.Any(p => p.Element == command))
                    {
                        trainer.Badges += 1;
                    }
                    else
                    {
                        for (int i = 0; i < trainer.Pokemons.Count; i++)
                        {
                            Pokemon currentPokemon = trainer.Pokemons[i];
                            currentPokemon.Health -= 10;
                            if (currentPokemon.Health <= 0)
                            {
                                trainer.Pokemons.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                }
            }

            foreach (var trainer in trainers.OrderByDescending(t => t.Badges))
            {
                Console.WriteLine($"{trainer.Name} {trainer.Badges} {trainer.Pokemons.Count}");
            }
        }
Пример #19
0
        public static void Main(string[] args)
        {
            string input = Console.ReadLine();

            List <Trainer> trainers = new List <Trainer>();

            while (input != "Tournament")
            {
                string[] trainerData    = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   trainerName    = trainerData[0];
                string   pokemonName    = trainerData[1];
                string   pokemonElement = trainerData[2];
                int      pokemonHealth  = int.Parse(trainerData[3]);

                Pokemon pokemon   = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                bool    isTrainer = false;

                foreach (var tr in trainers)
                {
                    if (tr.Name == trainerName)
                    {
                        tr.Pokemons.Add(pokemon);
                        isTrainer = true;
                        break;
                    }
                }

                if (!isTrainer)
                {
                    Trainer trainer = new Trainer(trainerName);
                    trainer.Pokemons.Add(pokemon);
                    trainers.Add(trainer);
                }

                input = Console.ReadLine();
            }

            input = Console.ReadLine();

            while (input != "End")
            {
                foreach (var trainer in trainers)
                {
                    bool hasElelement = false;

                    foreach (var pokemon in trainer.Pokemons.Where(x => x.Health > 0))
                    {
                        if (pokemon.Element == input)
                        {
                            hasElelement = true;
                            break;
                        }
                    }

                    if (hasElelement)
                    {
                        trainer.Badges++;
                    }
                    else
                    {
                        trainer.Pokemons.ForEach(x => x.Health -= 10);
                    }
                }

                input = Console.ReadLine();
            }

            trainers = trainers.OrderByDescending(x => x.Badges).ToList();

            foreach (var trainer in trainers)
            {
                Console.WriteLine(trainer);
            }
        }
Пример #20
0
        static void Main(string[] args)
        {
            List <Trainer> trainers = new List <Trainer>();
            List <Pokemon> pokemons = new List <Pokemon>();

            while (true)
            {
                var input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (input[0].Equals("Tournament"))
                {
                    break;
                }

                var     trainerName    = input[0];
                var     pokemonName    = input[1];
                var     pokemonElement = input[2];
                var     pokemonHealth  = int.Parse(input[3]);
                Pokemon pokemon        = new Pokemon
                {
                    Name    = pokemonName,
                    Element = pokemonElement,
                    Health  = pokemonHealth
                };
                pokemons.Add(pokemon);
                if (trainers.Any(a => a.Name == trainerName))
                {
                    trainers.FirstOrDefault(n => n.Name == trainerName).Pokemons.Add(pokemon);
                }
                else
                {
                    Trainer trainer = new Trainer
                    {
                        Name = trainerName,
                    };
                    trainer.Pokemons.Add(pokemon);
                    trainers.Add(trainer);
                }
            }

            while (true)
            {
                var input = Console.ReadLine();
                if (input.Equals("End"))
                {
                    break;
                }
                if (input.Equals("Fire"))
                {
                    foreach (var trainer in trainers)
                    {
                        if (trainer.Pokemons.Any(p => p.Element == "Fire"))
                        {
                            trainer.Badges++;
                        }
                        else
                        {
                            for (int i = 0; i < trainer.Pokemons.Count; i++)
                            {
                                trainer.Pokemons[i].Health -= 10;
                                if (trainer.Pokemons[i].Health <= 0)
                                {
                                    trainer.Pokemons.Remove(trainer.Pokemons[i]);
                                    i--;
                                }
                            }
                        }
                    }
                }

                if (input.Equals("Water"))
                {
                    foreach (var trainer in trainers)
                    {
                        if (trainer.Pokemons.Any(p => p.Element == "Water"))
                        {
                            trainer.Badges++;
                        }
                        else
                        {
                            for (int i = 0; i < trainer.Pokemons.Count; i++)
                            {
                                trainer.Pokemons[i].Health -= 10;
                                if (trainer.Pokemons[i].Health <= 0)
                                {
                                    trainer.Pokemons.Remove(trainer.Pokemons[i]);
                                    i--;
                                }
                            }
                        }
                    }
                }

                if (input.Equals("Electricity"))
                {
                    foreach (var trainer in trainers)
                    {
                        if (trainer.Pokemons.Any(p => p.Element == "Electricity"))
                        {
                            trainer.Badges++;
                        }
                        else
                        {
                            for (int i = 0; i < trainer.Pokemons.Count; i++)
                            {
                                trainer.Pokemons[i].Health -= 10;
                                if (trainer.Pokemons[i].Health <= 0)
                                {
                                    trainer.Pokemons.Remove(trainer.Pokemons[i]);
                                    i--;
                                }
                            }
                        }
                    }
                }
            }

            foreach (var trainer in trainers.OrderByDescending(a => a.Badges))
            {
                Console.WriteLine($"{trainer.Name} {trainer.Badges} {trainer.Pokemons.Count}");
            }
        }
Пример #21
0
        static void Main(string[] args)
        {
            var trainers = new List <Trainer>();

            while (true)
            {
                string line = Console.ReadLine();
                if (line == "Tournament")
                {
                    break;
                }

                string[] inputs = line.Split(' ');

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

                Trainer trainer = null;
                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                foreach (var item in trainers)
                {
                    if (item.Name == trainerName)
                    {
                        trainer = item;
                        break;
                    }
                }

                if (trainer == null)
                {
                    trainer = new Trainer(trainerName);
                    trainers.Add(trainer);
                }

                trainer.Pokemon.Add(pokemon);
            }

            while (true)
            {
                string line = Console.ReadLine();
                if (line == "End")
                {
                    break;
                }

                foreach (var trainer in trainers)
                {
                    trainer.ChallengePokemon(line);
                }
            }

            Console.WriteLine();

            for (int i = 0; i < trainers.Count - 1; ++i)
            {
                for (int j = i + 1; j < trainers.Count; ++j)
                {
                    if (trainers[i].NumberOfBadges < trainers[j].NumberOfBadges)
                    {
                        (trainers[i], trainers[j]) = (trainers[j], trainers[i]);
                    }
                }
            }

            foreach (var trainer in trainers)
            {
                Console.WriteLine(trainer);
            }

            Console.ReadKey();
        }
Пример #22
0
        static void Main(string[] args)
        {
            List <Trainer> trainersCollection = new List <Trainer>();


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

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

                List <string> inputParameters = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();

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

                Pokemon b = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                if (trainersCollection.Any(x => x.Name == trainerName))
                {
                    Trainer t = trainersCollection.First(x => x.Name == trainerName);

                    t.PokemonCollection.Add(b);
                }
                else
                {
                    Trainer a = new Trainer(trainerName);
                    a.PokemonCollection.Add(b);
                    trainersCollection.Add(a);
                }
            }

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

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

                for (int i = 0; i < trainersCollection.Count; i++)
                {
                    if (trainersCollection[i].PokemonCollection.Any(x => x.Element == command))
                    {
                        trainersCollection[i].NumberOfBadges++;
                    }
                    else
                    {
                        for (int j = 0; j < trainersCollection[i].PokemonCollection.Count; j++)
                        {
                            trainersCollection[i].PokemonCollection[j].Health -= 10;

                            if (trainersCollection[i].PokemonCollection[j].Health <= 0)
                            {
                                trainersCollection[i].PokemonCollection.RemoveAt(j);
                                j--;
                            }
                        }
                    }
                }
            }

            var sortedCollection = trainersCollection.OrderByDescending(x => x.NumberOfBadges);

            foreach (var element in sortedCollection)
            {
                Console.WriteLine(element);
            }
        }
Пример #23
0
        static void Main(string[] args)
        {
            List <Trainer> trainers = new List <Trainer>();

            while (true)
            {
                string input = Console.ReadLine();
                if (input == "Tournament")
                {
                    break;
                }
                else
                {
                    var caugthPokemonInfo = input
                                            .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                            .ToArray();
                    var     trainerName    = caugthPokemonInfo[0];
                    var     pokemonName    = caugthPokemonInfo[1];
                    var     pokemonElement = caugthPokemonInfo[2];
                    var     pokemonHealth  = int.Parse(caugthPokemonInfo[3]);
                    int     trainerBadges  = 0;
                    Pokemon pokemon        = new Pokemon(pokemonName, pokemonElement, pokemonHealth);


                    if (trainers.Any(t => t.Name == trainerName))
                    {
                        foreach (var trainer in trainers)
                        {
                            if (trainer.Name == trainerName)
                            {
                                trainer.CaugthPokemons.Add(pokemon);
                            }
                        }
                    }
                    else
                    {
                        List <Pokemon> caugthPokemons = new List <Pokemon>();
                        caugthPokemons.Add(pokemon);
                        Trainer trainer = new Trainer(trainerName, trainerBadges, caugthPokemons);
                        trainers.Add(trainer);
                    }
                }
            }

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

                if (elementName == "End")
                {
                    break;
                }
                else
                {
                    foreach (var trainer in trainers)
                    {
                        if (trainer.CaugthPokemons.Any(p => p.Element == elementName))
                        {
                            trainer.NumberBadges++;
                        }


                        if (trainer.CaugthPokemons.All(p => p.Element != elementName))
                        {
                            for (int i = 0; i < trainer.CaugthPokemons.Count; i++)
                            {
                                trainer.CaugthPokemons[i].Health -= 10;
                                if (trainer.CaugthPokemons[i].Health <= 0)
                                {
                                    trainer.CaugthPokemons.Remove(trainer.CaugthPokemons[i]);
                                    i--;
                                }
                            }
                        }
                    }
                }
            }

            foreach (var trainer in trainers.OrderByDescending(t => t.NumberBadges))
            {
                Console.WriteLine($"{trainer.Name} {trainer.NumberBadges} {trainer.CaugthPokemons.Count}");
            }
        }
Пример #24
0
        static void Main(string[] args)
        {
            string         input          = string.Empty;
            List <Trainer> listOfTrainers = new List <Trainer>();

            while ((input = Console.ReadLine()) != "Tournament")
            {
                string[] data           = input.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray();
                string   nameTrainer    = data[0];
                string   namePokemon    = data[1];
                string   elementPokemon = data[2];
                int      healthPokemon  = int.Parse(data[3]);
                int      numOfBadges    = 0;

                Pokemon currPokemon = new Pokemon(namePokemon, elementPokemon, healthPokemon);


                if (listOfTrainers.Exists(x => x.Name == nameTrainer) == false)
                {
                    List <Pokemon> listOfPokemons = new List <Pokemon>();
                    listOfPokemons.Add(currPokemon);
                    Trainer currTrainer = new Trainer(nameTrainer, numOfBadges, listOfPokemons);
                    listOfTrainers.Add(currTrainer);
                }
                else
                {
                    var tu = listOfTrainers.Single(x => x.Name == nameTrainer);
                    tu.Pokemons.Add(currPokemon);
                }
            }

            string badge = string.Empty;

            while ((badge = Console.ReadLine()) != "End")
            {
                for (int i = 0; i < listOfTrainers.Count; i++)
                {
                    string nameTrainer = listOfTrainers[i].Name;

                    if (listOfTrainers[i].Pokemons.Exists(x => x.Element == badge))
                    {
                        listOfTrainers[i].NumOfBadges++;
                    }
                    else
                    {
                        var tu = listOfTrainers.Single(x => x.Name == nameTrainer);

                        for (int z = 0; z < listOfTrainers[i].Pokemons.Count; z++)
                        {
                            listOfTrainers[i].Pokemons[z].Health -= 10;
                            bool isDied = listOfTrainers[i].Pokemons.Exists(x => x.Health <= 0);

                            if (isDied)
                            {
                                tu.Pokemons.RemoveAll(x => x.Health < 0);
                                z--;
                            }
                        }
                    }
                }
            }

            foreach (var item in listOfTrainers.OrderByDescending(x => x.NumOfBadges))
            {
                Console.WriteLine($"{item.Name} {item.NumOfBadges} {item.Pokemons.Count}");
            }
        }
Пример #25
0
        public static void Main()
        {
            List <Trainer> trainers = new List <Trainer>();

            while (true)
            {
                string[] input = Console.ReadLine()
                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                if (input[0] == "Tournament")
                {
                    break;
                }

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

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                if (!trainers.Any(t => t.Name == trainerName))
                {
                    Trainer newTrainer = new Trainer(trainerName);
                    newTrainer.AddPokemon(pokemon);
                    trainers.Add(newTrainer);
                }
                else
                {
                    var currentTrainer = trainers.FirstOrDefault(t => t.Name == trainerName);
                    currentTrainer.CollectionOfPokemon.Add(pokemon);
                }
            }

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

                if (element == "End")
                {
                    break;
                }
                else if (element != "Fire" && element != "Water" && element != "Electricity")
                {
                    continue;
                }

                foreach (var trainer in trainers)
                {
                    if (trainer.CollectionOfPokemon.Any(x => x.Element == element))
                    {
                        trainer.AddBadges();
                    }
                    else
                    {
                        trainer.ReduciceHealth();
                        trainer.RemovePokemon();
                    }
                }
            }

            foreach (var item in trainers.OrderByDescending(x => x.NumberOfBadges))
            {
                Console.WriteLine(item);
            }
        }
Пример #26
0
        static void Main(string[] args)
        {
            List <Trainer> trainers = new List <Trainer>();
            List <Pokemon> pokemons = new List <Pokemon>();

            while (true)
            {
                var input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray();

                if (input[0].Equals("Tournament"))
                {
                    break;
                }

                //"{trainerName} {pokemonName} {pokemonElement} {pokemonHealth}"

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

                if (trainers.Any(x => x.Name.Equals(trainerName)))
                {
                    Trainer tempTrainer = trainers.FirstOrDefault(x => x.Name == trainerName);

                    int index = trainers.IndexOf(tempTrainer);

                    trainers[index].CollectionOfPokemons.Add(new Pokemon(pokemonName, pokemonElement, pokemonHealt));
                    continue;
                }

                trainers.Add(new Trainer(trainerName, new List <Pokemon>()));

                trainers[trainers.Count - 1].CollectionOfPokemons.Add(new Pokemon(pokemonName, pokemonElement, pokemonHealt));
            }

            while (true)
            {
                var command = Console.ReadLine();

                if (command.Equals("End"))
                {
                    break;
                }

                if (command.Equals("Fire"))
                {
                    Trainer.PokemonAtak(trainers, command);
                }
                else if (command.Equals("Water"))
                {
                    Trainer.PokemonAtak(trainers, command);
                }
                else if (command.Equals("Electricity"))
                {
                    Trainer.PokemonAtak(trainers, command);
                }
            }
            foreach (var trainer in trainers.OrderByDescending(x => x.NumberOfBadges))
            {
                Console.WriteLine($"{trainer.Name} {trainer.NumberOfBadges} {trainer.CollectionOfPokemons.Count()}");
            }
        }
        static void Main()
        {
            List <Trainer> trainers = new List <Trainer>();

            string command = Console.ReadLine();

            while (command != "Tournament")
            {
                string[] commandArguments = command
                                            .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                            .ToArray();

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

                Trainer trainer = new Trainer(trainerName);
                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                var targetTrainer = trainers.FirstOrDefault(x => x.Name == trainerName);

                if (targetTrainer == null)
                {
                    trainers.Add(trainer);
                    trainer.CollectionOfPokemons.Add(pokemon);
                }
                else
                {
                    targetTrainer.CollectionOfPokemons.Add(pokemon);
                }

                command = Console.ReadLine();
            }

            string InputElement = Console.ReadLine();

            while (InputElement != "End")
            {
                foreach (var currentTrainer in trainers)
                {
                    if (currentTrainer.CollectionOfPokemons.Any(x => x.Element == InputElement))
                    {
                        currentTrainer.Badges++;
                    }
                    else
                    {
                        if (currentTrainer.CollectionOfPokemons.Any())
                        {
                            foreach (var pokemon in currentTrainer.CollectionOfPokemons.OrderByDescending(x => x.Health))
                            {
                                pokemon.Health -= 10;

                                if (pokemon.Health <= 0)
                                {
                                    currentTrainer.CollectionOfPokemons.Remove(pokemon);

                                    if (!currentTrainer.CollectionOfPokemons.Any())
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                InputElement = Console.ReadLine();
            }

            foreach (var trainer in trainers.OrderByDescending(x => x.Badges))
            {
                Console.WriteLine($"{trainer.Name} {trainer.Badges} {trainer.CollectionOfPokemons.Count}");
            }
        }
Пример #28
0
        static void Main()
        {
            var trainersData  = new Dictionary <string, Trainer>();
            var elementsStats = new Dictionary <string, Dictionary <string, List <Pokemon> > >();

            string input = Console.ReadLine();

            while (input != "Tournament")
            {
                var tokens = input.Split(new char[] { ' ' },
                                         StringSplitOptions.RemoveEmptyEntries);
                string trainerName    = tokens[0];
                string pokemonName    = tokens[1];
                string pokemonElement = tokens[2];
                int    pokemonHealth  = int.Parse(tokens[3]);

                if (trainersData.ContainsKey(trainerName) == false)
                {
                    var trainer = new Trainer(trainerName);
                    trainersData.Add(trainerName, trainer);
                    elementsStats.Add(trainerName, new Dictionary <string, List <Pokemon> >());

                    elementsStats[trainerName].Add("Fire", new List <Pokemon>());
                    elementsStats[trainerName].Add("Water", new List <Pokemon>());
                    elementsStats[trainerName].Add("Electricity", new List <Pokemon>());
                }



                //elementsStats[trainerName][pokemonElement] += 1;

                // Console.WriteLine("EL: " + pokemonElement);
                var pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                trainersData[trainerName].AddPokemon(pokemon);

                if (elementsStats[trainerName].ContainsKey(pokemonElement))
                {
                    elementsStats[trainerName][pokemonElement].Add(pokemon);
                }
                input = Console.ReadLine();
            }

            /*
             * foreach(var trainer in elementsStats)
             * {
             *  Console.WriteLine(trainer.Key);
             *
             *  foreach(var data in trainer.Value)
             *  {
             *      Console.WriteLine(data.Key + " " + data.Value.Count);
             *  }
             * }
             */
            string command = Console.ReadLine();

            while (command != "End")
            {
                if (command == "Fire" || command == "Water" || command == "Electricity")
                {
                    foreach (var data in elementsStats)
                    {
                        string trainer = data.Key;

                        if (elementsStats[trainer][command].Count > 0)
                        {
                            trainersData[trainer].AddOneBadge();
                        }
                        else
                        {
                            trainersData[trainer].RemovePokemons();

                            // var trainerPokemons = trainersData[trainer].Pokemons;

                            /*
                             * foreach (var me in elementsStats[trainer])
                             * {
                             *  if(me.Key != command)
                             *  {
                             * Console.WriteLine(me.Key + " " + me.Value.Count);
                             *  }
                             *
                             *  // Console.WriteLine(pokemon.Name + " " + pokemon.Health);
                             * }
                             */

                            // elementsStats[trainer]

                            /* foreach (var pokemon in trainerPokemons)
                             *   {
                             *
                             *       Console.WriteLine(pokemon.Name + " " + pokemon.Element);
                             *   }
                             */
                        }
                    }
                }
                command = Console.ReadLine();
            }

            var sortedData = trainersData.OrderByDescending(x => x.Value.Badges)
                             .ToDictionary(x => x.Key, x => x.Value);

            foreach (var data in sortedData)
            {
                string trainerName = data.Key;
                var    trainerData = data.Value;

                int pokemonsCount = trainerData.Pokemons.Where(p => p != null).Count();
                Console.WriteLine($"{trainerName} {trainerData.Badges} {pokemonsCount}");
            }
        }
Пример #29
0
        static void Main(string[] args)
        {
            List <Trainer> trainers = new List <Trainer>();

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "Tournament")
            {
                string[] tokens = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);

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

                if (!trainers.Any(x => x.Name == trainerName))
                {
                    List <Pokemon> newList    = new List <Pokemon>();
                    Trainer        newTrainer = new Trainer(trainerName, newList);
                    trainers.Add(newTrainer);
                }

                Trainer trainerToFind  = trainers.Where(x => x.Name == trainerName).FirstOrDefault();
                int     indexOfTrainer = trainers.IndexOf(trainerToFind);

                Pokemon newPokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                trainers[indexOfTrainer].Pokemons.Add(newPokemon);
            }

            string element = string.Empty;

            while ((element = Console.ReadLine()) != "End")
            {
                foreach (var trainer in trainers)
                {
                    if (trainer.Pokemons.Any(x => x.Element == element))
                    {
                        trainer.Badges++;
                    }
                    else
                    {
                        foreach (var pokemon in trainer.Pokemons)
                        {
                            pokemon.Health -= 10;
                        }
                    }
                }

                foreach (var item in trainers)
                {
                    foreach (var pokemon in item.Pokemons)
                    {
                        if (pokemon.Health <= 0)
                        {
                            pokemon.Element = "Dead";
                        }
                    }
                }
            }

            foreach (Trainer trainer in trainers.OrderByDescending(x => x.Badges))
            {
                Console.WriteLine(trainer.ToString());
            }
        }
        static void Main(string[] args)
        {
            int    count         = 0;
            int    pokemonsCount = 0;
            string line;

            trainers = new List <Trainer>();
            while ((line = Console.ReadLine().Trim()) != "Tournament")
            {
                string[] input = line.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                // string name, string PokemonName, string PokemonElement, int PokemonHealth
                string  name           = input[0];
                string  PokemonName    = input[1];
                string  PokemonElement = input[2];
                int     PokemonHealth  = int.Parse(input[3]);
                Trainer trainer;
                if ((trainer = GetTrainer(name)) == null)
                {
                    trainer = new Trainer(name, PokemonName, PokemonElement, PokemonHealth);
                    trainers.Add(trainer);
                }
                else
                {
                    trainer.AddPokemon(PokemonName, PokemonElement, PokemonHealth);
                }
            }

            while ((line = Console.ReadLine().Trim()) != "End")
            {
                foreach (var currentTrainer in trainers)
                {
                    foreach (var pokemon in currentTrainer.PokemonList)
                    {
                        if (pokemon.Element == line && pokemon.Health > 0)
                        {
                            count++;
                        }
                    }
                    if (count > 0)
                    {
                        currentTrainer.Badges++;
                    }
                    else
                    {
                        foreach (var pokemon in currentTrainer.PokemonList)
                        {
                            pokemon.Health -= 10;
                        }
                    }
                    count = 0;
                }
            }

            foreach (var currentTrainer in trainers.OrderByDescending(x => x.Badges))
            {
                foreach (var pokemon in currentTrainer.PokemonList)
                {
                    if (pokemon.Health > 0)
                    {
                        pokemonsCount++;
                    }
                }
                Console.WriteLine($"{currentTrainer.name} {currentTrainer.Badges} {pokemonsCount}");
                pokemonsCount = 0;
            }
        }