Advertisement
jwrbg

Untitled

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