Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class PokemonEvolution {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- Map<String, List<String>> pokemons = new LinkedHashMap<>();
- while (!input.equals("wubbalubbadubdub")) {
- if (input.contains("->")) {
- String[] tokens = input.split(" -> ");
- String pokemonName = tokens[0];
- String evolutionType = tokens[1];
- String evolutionIndex = tokens[2];
- String evolutionTypeIndex = evolutionType + " <-> " + evolutionIndex;
- if (!pokemons.containsKey(pokemonName)) {
- pokemons.put(pokemonName, new ArrayList<>());
- pokemons.get(pokemonName).add(evolutionTypeIndex);
- } else {
- pokemons.get(pokemonName).add(evolutionTypeIndex);
- }
- } else {
- String pokemonName = input;
- if (pokemons.containsKey(pokemonName)) {
- System.out.println("# " + pokemonName);
- for (String s : pokemons.get(pokemonName)) {
- System.out.println(s);
- }
- }
- }
- input = scanner.nextLine();
- }
- pokemons.forEach((name, evolutions) -> {
- System.out.printf("# %s%n", name);
- evolutions.stream()
- .sorted((f, s) -> {
- int sEvolution = Integer.parseInt(s.split(" <-> ")[1]);
- int fEvolution = Integer.parseInt(f.split(" <-> ")[1]);
- return sEvolution - fEvolution;
- })
- .forEach(System.out::println);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment