Advertisement
Guest User

Untitled

a guest
Jun 10th, 2019
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.99 KB | None | 0 0
  1. package PokemonTrainer;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         Pokemon pokemon = null;
  9.         LinkedHashMap<String, List<Pokemon>> trainerInfo = new LinkedHashMap<>();
  10.         Trainer trainer = null;
  11.         LinkedHashMap<String, Trainer> trainersPrinted = new LinkedHashMap<>();
  12.  
  13.         String[] input = scanner.nextLine().split("\\s+");
  14.         while (!input[0].equals("Tournament")) {
  15.             String trainerName = input[0];
  16.             String pokemonName = input[1];
  17.             String pokemonElement = input[2];
  18.             int pokemonHealth = Integer.parseInt(input[3]);
  19.             pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
  20.             trainerInfo.putIfAbsent(trainerName, new ArrayList<>());
  21.             trainerInfo.get(trainerName).add(pokemon);
  22.             trainer = new Trainer(trainerName, 0, 0);
  23.             trainersPrinted.putIfAbsent(trainerName, trainer);
  24.  
  25.  
  26.             input = scanner.nextLine().split("\\s+");
  27.  
  28.         }
  29.         String line = scanner.nextLine();
  30.         while (!line.equals("End")) {
  31.             String element = line;
  32.             boolean elementFound = false;
  33.  
  34.             for (Map.Entry<String, List<Pokemon>> a : trainerInfo.entrySet()) {
  35.                 for (Pokemon z : a.getValue()) {
  36.                     if (z.getElement().equals(element)) {
  37.                         trainersPrinted.get(a.getKey()).setNumBadges();
  38.                         elementFound = true;
  39.                         break;
  40.                     }
  41.                 }
  42.                 if (!elementFound) {
  43.                     ArrayDeque<Integer> deadPokemonIndexes = new ArrayDeque<>();
  44.  
  45.                     for (int i = 0; i < a.getValue().size(); i++) {
  46.                         Pokemon currentPokemon = a.getValue().get(i);
  47.                         currentPokemon.damagePokemon();
  48.                         if (currentPokemon.getHealth() <= 0) {
  49.                             deadPokemonIndexes.push(i);
  50.                         }
  51.                     }
  52.                     while (!deadPokemonIndexes.isEmpty()) {
  53.                         int index = deadPokemonIndexes.pop();
  54.                         a.getValue().remove(index);
  55.  
  56.                     }
  57.                 }
  58.             }
  59.             line = scanner.nextLine();
  60.         }
  61.         trainersPrinted.entrySet().stream().forEach(a -> {
  62.             trainerInfo.entrySet().stream().forEach(b -> {
  63.                 if (a.getKey().contains(b.getKey())) {
  64.  
  65.  
  66.                     a.getValue().setPokemonCollections(b.getValue().size());
  67.                 }
  68.             });
  69.         });
  70.         trainersPrinted.entrySet().stream().sorted((a, b) -> Integer.compare(b.getValue().getNumBadges(), a.getValue().getNumBadges())).forEach(a -> {
  71.             System.out.println(String.format("%s %d %d", a.getValue().getName(), a.getValue().getNumBadges(), a.getValue().getPokemonCollections()));
  72.         });
  73.  
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement