|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | + |
| 5 | +namespace PokemonTrainer |
| 6 | +{ |
| 7 | + public class Program |
| 8 | + { |
| 9 | + static void Main(string[] args) |
| 10 | + { |
| 11 | + List<Trainer> trainers = new List<Trainer>(); |
| 12 | + string command = Console.ReadLine(); |
| 13 | + |
| 14 | + while (command != "Tournament") |
| 15 | + { |
| 16 | + string[] operations = command.Split(" ", StringSplitOptions.RemoveEmptyEntries); |
| 17 | + string trainerName = operations[0]; |
| 18 | + string pokeName = operations[1]; |
| 19 | + string element = operations[2]; |
| 20 | + int health = int.Parse(operations[3]); |
| 21 | + Trainer trainer = new Trainer(trainerName, 0, new List<Pokemon>()); |
| 22 | + Pokemon pokemon = new Pokemon(pokeName, element, health); |
| 23 | + |
| 24 | + if (!trainers.Any(x => x.Name == trainerName)) |
| 25 | + { |
| 26 | + trainers.Add(trainer); |
| 27 | + } |
| 28 | + trainers.First(x => x.Name == trainerName).Pokemons.Add(pokemon); |
| 29 | + |
| 30 | + command = Console.ReadLine(); |
| 31 | + } |
| 32 | + |
| 33 | + string elem = Console.ReadLine(); |
| 34 | + |
| 35 | + while (elem != "End") |
| 36 | + { |
| 37 | + foreach (Trainer trainer in trainers) |
| 38 | + { |
| 39 | + if (trainer.Pokemons.Any(p => p.Element == elem)) |
| 40 | + { |
| 41 | + trainer.Badges++; |
| 42 | + } |
| 43 | + else |
| 44 | + { |
| 45 | + for (int i = 0; i < trainer.Pokemons.Count; i++) |
| 46 | + { |
| 47 | + trainer.Pokemons[i].Health -= 10; |
| 48 | + if (trainer.Pokemons[i].Health <= 0) |
| 49 | + { |
| 50 | + trainer.Pokemons.Remove(trainer.Pokemons[i]); |
| 51 | + i--; |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + elem = Console.ReadLine(); |
| 57 | + } |
| 58 | + |
| 59 | + Console.WriteLine(string.Join(Environment.NewLine, trainers.OrderByDescending(t => t.Badges))); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments