static void Main(string[] args) { Dictionary <string, Trainers> trainers = new Dictionary <string, Trainers>(); string command; while ((command = Console.ReadLine()) != "Tournament") { string[] curCommand = command.Split(' ', StringSplitOptions.RemoveEmptyEntries); string trainerName = curCommand[0]; string pokemonName = curCommand[1]; string pokemonElement = curCommand[2]; string pokemonHealth = curCommand[3]; Pokemon curPokemon = new Pokemon(pokemonName, pokemonElement, int.Parse(pokemonHealth)); Trainers curTrainer = new Trainers(trainerName, curPokemon); if (!trainers.ContainsKey(trainerName)) { trainers[trainerName] = curTrainer; } else { trainers[trainerName].PokemonsColection.Add(curPokemon); } } string secondCommand; while ((secondCommand = Console.ReadLine()) != "End") { foreach (var item in trainers) { bool noPokemonElementFound = true; foreach (var pokemon in item.Value.PokemonsColection) { if (pokemon.Element == secondCommand) { item.Value.Badges++; noPokemonElementFound = false; break; } } if (noPokemonElementFound) { foreach (var pokemon in item.Value.PokemonsColection) { pokemon.Health -= 10; } } item.Value.PokemonsColection = item.Value.RemoveDeathPokemons(item.Value.PokemonsColection); } } trainers = trainers.OrderByDescending(trainer => trainer.Value.Badges).ToDictionary(x => x.Key, y => y.Value); foreach (var trainer in trainers) { Console.WriteLine($"{trainer.Value.Name} {trainer.Value.Badges} {trainer.Value.PokemonsColection.Count}"); } }
static void Main(string[] args) { var trainersAndPokemons = new List <Trainers>(); while (true) { var command = Console.ReadLine().Split(); if (command[0] == "Tournament") { break; } var trainerName = command[0]; var pokemonName = command[1]; var pokemonElement = command[2]; var pokemonHealth = double.Parse(command[3]); var pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth); if (trainersAndPokemons.Any(x => x.TrainerName == trainerName)) { foreach (var trainer1 in trainersAndPokemons) { if (trainer1.TrainerName == trainerName) { trainer1.Pokemons.Add(pokemon); } } } else { var trainer = new Trainers(trainerName, 0, 0, new List <Pokemon>()); trainer.Pokemons.Add(pokemon); trainersAndPokemons.Add(trainer); } } while (true) { var command = Console.ReadLine(); if (command == "End") { break; } if (command == "Fire") { for (int i = 0; i < trainersAndPokemons.Count; i++) { if (trainersAndPokemons[i].Pokemons.Any(x => x.PokemonElement == "Fire")) { trainersAndPokemons[i].NumberOfBadges++; } else { for (int k = 0; k < trainersAndPokemons[i].Pokemons.Count; k++) { if (trainersAndPokemons[i].Pokemons[k].PokemonElement != "Fire") { trainersAndPokemons[i].Pokemons[k].PokemonHealth -= 10; if (trainersAndPokemons[i].Pokemons[k].PokemonHealth <= 0) { trainersAndPokemons[i].Pokemons.Remove(trainersAndPokemons[i].Pokemons[k]); } } } } } } else if (command == "Water") { for (int i = 0; i < trainersAndPokemons.Count; i++) { if (trainersAndPokemons[i].Pokemons.Any(x => x.PokemonElement == "Water")) { trainersAndPokemons[i].NumberOfBadges++; } else { for (int k = 0; k < trainersAndPokemons[i].Pokemons.Count; k++) { if (trainersAndPokemons[i].Pokemons[k].PokemonElement != "Water") { trainersAndPokemons[i].Pokemons[k].PokemonHealth -= 10; if (trainersAndPokemons[i].Pokemons[k].PokemonHealth <= 0) { trainersAndPokemons[i].Pokemons.Remove(trainersAndPokemons[i].Pokemons[k]); } } } } } } else if (command == "Electricity") { for (int i = 0; i < trainersAndPokemons.Count; i++) { if (trainersAndPokemons[i].Pokemons.Any(x => x.PokemonElement == "Electricity")) { trainersAndPokemons[i].NumberOfBadges++; } else { for (int k = 0; k < trainersAndPokemons[i].Pokemons.Count; k++) { if (trainersAndPokemons[i].Pokemons[k].PokemonElement != "Water") { trainersAndPokemons[i].Pokemons[k].PokemonHealth -= 10; if (trainersAndPokemons[i].Pokemons[k].PokemonHealth <= 0) { trainersAndPokemons[i].Pokemons.Remove(trainersAndPokemons[i].Pokemons[k]); } } } } } } } foreach (var trainer in trainersAndPokemons.OrderByDescending(x => x.NumberOfBadges)) { Console.WriteLine($"{trainer.TrainerName} {trainer.NumberOfBadges} {trainer.Pokemons.Count}"); } }