示例#1
0
        static void Main()
        {
            string         line;
            List <Trainer> trainers = new List <Trainer>();

            while ((line = Console.ReadLine()) != "Tournament")
            {
                var     info           = line.Split();
                var     trainerName    = info[0];
                var     pokemonName    = info[1];
                var     pokemonElement = info[2];
                var     pokemonHealth  = int.Parse(info[3]);
                Pokemon pokemon        = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                Trainer trainer = new Trainer(trainerName, pokemon);

                if (!trainers.Any(t => t.Name == trainerName))
                {
                    trainers.Add(trainer);
                }
                else
                {
                    var tr = trainers.First(t => t.Name == trainerName);
                    tr.pokemons.Add(pokemon);
                }
            }

            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                foreach (var tr in trainers)
                {
                    if (tr.pokemons.Any(p => p.Element == command))
                    {
                        tr.AddBadge();
                    }
                    else
                    {
                        foreach (var pokemon in tr.pokemons)
                        {
                            pokemon.Health -= 10;
                        }

                        for (int i = 0; i < tr.pokemons.Count; i++)
                        {
                            if (tr.pokemons[i].Health <= 0)
                            {
                                tr.pokemons.Remove(tr.pokemons[i]);
                                i++;
                            }
                        }
                    }
                }
            }

            foreach (var t in trainers.OrderByDescending(b => b.Badges))
            {
                Console.WriteLine($"{t.Name} {t.Badges} {t.pokemons.Count}");
            }
        }
示例#2
0
        public static void Main()
        {
            var trainers = new List <Trainer>();

            while (true)
            {
                var inputLine = Console.ReadLine();
                if (inputLine.Equals("Tournament"))
                {
                    break;
                }

                var trainerInfo    = inputLine.Split().Where(e => e != string.Empty).ToArray();
                var trainerName    = trainerInfo[0];
                var pokemonName    = trainerInfo[1];
                var pokemonElement = trainerInfo[2];
                var pokemonHealth  = int.Parse(trainerInfo[3]);

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

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

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

            var element = Console.ReadLine();

            while (!element.Equals("End"))
            {
                for (int i = 0; i < trainers.Count; i++)
                {
                    var currentTrainer = trainers[i];
                    if (currentTrainer.Pokemons.Any(p => p.Element.Equals(element)))
                    {
                        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--;
                            }
                        }
                    }
                }

                element = Console.ReadLine();
            }

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

            foreach (var trainer in trainers)
            {
                Console.WriteLine($"{trainer.Name} {trainer.Badges} {trainer.Pokemons.Count}");
            }
        }
示例#3
0
        public static void Main(string[] args)
        {
            var trainers = new List <Trainer>();
            var line     = string.Empty;

            while ((line = Console.ReadLine()) != "Tournament")
            {
                var lineTokens = line
                                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                 .ToArray();

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

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

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

                if (currentTraniner
                    .Pokemons
                    .All(p => p.Name != pokemonName))
                {
                    var pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                    currentTraniner.Pokemons.Add(pokemon);
                }
                else
                {
                    currentTraniner
                    .Pokemons
                    .FirstOrDefault(p => p.Name == pokemonName)
                    .Element = pokemonElement;

                    currentTraniner
                    .Pokemons
                    .FirstOrDefault(p => p.Name == pokemonName)
                    .Health += pokemonHealth;
                }
            }

            var elements = string.Empty;

            while ((elements = Console.ReadLine()) != "End")
            {
                foreach (var currentTrainer in trainers)
                {
                    if (currentTrainer
                        .Pokemons
                        .Any(p => p.Element == elements))
                    {
                        currentTrainer.Badges++;
                    }
                    else
                    {
                        currentTrainer
                        .Pokemons
                        .ForEach(p => p.Health -= 10);

                        for (var 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.ToString());
            }
        }