SHARE
TWEET

Untitled

a guest Jun 10th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package PokemonTrainer;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.LinkedHashMap;
  7. import java.util.Map;
  8.  
  9. public class Main {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  12.  
  13.         Map<String, Trainer> trainers = new LinkedHashMap<>();
  14.  
  15.         String input;
  16.  
  17.         while (!"Tournament".equals(input = reader.readLine())) {
  18.             String[] data = input.split("\\s+");
  19.  
  20.             String trainerName = data[0];
  21.             String pokemonName = data[1];
  22.             String element = data[2];
  23.             int health = Integer.parseInt(data[3]);
  24.  
  25.             Pokemon pokemon = new Pokemon(pokemonName, element, health);
  26.  
  27.             trainers.putIfAbsent(trainerName, new Trainer());
  28.             trainers.get(trainerName).addPokemon(pokemon);
  29.  
  30.         }
  31.  
  32.         String command;
  33.  
  34.         while (!"End".equals(command = reader.readLine())) {
  35.  
  36.             for (Map.Entry<String, Trainer> kvp : trainers.entrySet()) {
  37.                 if (kvp.getValue().pokeCollectionSize() > 0) {
  38.                     boolean havePokemon = false;
  39.                     for (Pokemon pokemon : kvp.getValue().getPokemons()) {
  40.                         if (pokemon.getElement().equals(command)) {
  41.                             havePokemon = true;
  42.                             kvp.getValue().setNumOfBadges();
  43.                             break;
  44.                         }
  45.                     }
  46.                     if (!havePokemon) {
  47.                         kvp.getValue().missingPokemonPenalty();
  48.                     }
  49.                 }
  50.             }
  51.         }
  52.         trainers.entrySet().stream()
  53.                 .sorted((b1, b2) -> Integer.compare(b2.getValue().getNumOfBadges(), b1.getValue().getNumOfBadges()))
  54.                 .forEach(t -> {
  55.                     System.out.println(String.format("%s %s %s", t.getKey(),
  56.                             t.getValue().getNumOfBadges(),
  57.                             t.getValue().pokeCollectionSize()));
  58.                 });
  59.     }
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top