public static void Main(string[] args) { string[] command = Console.ReadLine() .Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); Dictionary <string, List <Pokemon> > trainersAndPokemons = new Dictionary <string, List <Pokemon> >(); while (command[0] != "Tournament") { string trainerName = command[0]; string pokemonName = command[1]; string pokemonElement = command[2]; int pokemonHealth = int.Parse(command[3]); Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth); if (!trainersAndPokemons.ContainsKey(trainerName)) { trainersAndPokemons[trainerName] = new List <Pokemon>(); } trainersAndPokemons[trainerName].Add(pokemon); command = Console.ReadLine() .Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); } List <Trainer> trainers = new List <Trainer>(); foreach (var trainerAndPokemon in trainersAndPokemons) { Trainer trainer = new Trainer(trainerAndPokemon.Key, trainerAndPokemon.Value); trainers.Add(trainer); } string input = Console.ReadLine(); while (input != "End") { foreach (var trainer in trainers) { bool containsElement = trainer.Pokemons.Any(x => x.Element.Equals(input)); if (containsElement) { trainer.WinsBadge(); } else { trainer.LosesHealth(trainer); } } input = Console.ReadLine(); } trainers = trainers.OrderByDescending(trainer => trainer.Badges).ToList(); foreach (var trainer in trainers) { Console.WriteLine($"{trainer.Name} {trainer.Badges} {trainer.Pokemons.Count}"); } }
static void Main(string[] args) { Dictionary <string, Trainer> trainers = new Dictionary <string, Trainer>(); while (true) { string input = Console.ReadLine(); if (input == "Tournament") { break; } string[] data = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); string trainerName = data[0]; string pokemonName = data[1]; string pokemonElement = data[2]; int pokemonHealth = int.Parse(data[3]); Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth); Trainer currentTrainer = new Trainer(trainerName); if (!trainers.ContainsKey(trainerName)) { trainers.Add(trainerName, currentTrainer); } trainers[trainerName].Pokemons.Add(pokemon); } while (true) { string command = Console.ReadLine(); if (command == "End") { break; } foreach ((string trainerName, Trainer trainer) in trainers) { if (trainer.Pokemons.Any(p => p.Element == command)) { trainer.Badges++; } else { foreach (var pokemon in trainer.Pokemons) { pokemon.Health -= 10; } trainer.Pokemons.RemoveAll(x => x.Health <= 0); } } } 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}"); } }