Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Advanced.DefiningClasses.PokemonTrainer;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.LinkedHashMap;
- import java.util.Map;
- public class Main {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- Map<String, Trainer> trainers = new LinkedHashMap<>();
- String input;
- while (!"Tournament".equals(input = reader.readLine())) {
- String[] data = input.split("\\s+");
- String trainerName = data[0];
- String pokemonName = data[1];
- String element = data[2];
- int health = Integer.parseInt(data[3]);
- Pokemon pokemon = new Pokemon(pokemonName, element, health);
- trainers.putIfAbsent(trainerName, new Trainer());
- trainers.get(trainerName).addPokemon(pokemon);
- }
- String command;
- while (!"End".equals(command = reader.readLine())) {
- for (Map.Entry<String, Trainer> kvp : trainers.entrySet()) {
- if (kvp.getValue().getPokemons().size() > 0) {
- for (Pokemon pokemon : kvp.getValue().getPokemons()) {
- boolean havePokemon = false;
- if (pokemon.getElement().equals(command)) {
- havePokemon = true;
- }
- if (havePokemon) {
- kvp.getValue().setNumOfBadges();
- break;
- } else {
- pokemon.lowerHealth();
- if (pokemon.getHealth() <= 0) {
- kvp.getValue().getPokemons().remove(pokemon);
- if (kvp.getValue().getPokemons().size() < 1) {
- break;
- }
- }
- }
- }
- }
- }
- }
- trainers.entrySet().stream()
- .sorted((b1, b2) -> Integer.compare(b2.getValue().getNumOfBadges(), b1.getValue().getNumOfBadges()))
- .forEach(t -> {
- System.out.println(String.format("%s %s %s", t.getKey(),
- t.getValue().getNumOfBadges(),
- t.getValue().getPokemons().size()));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement