Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exams.july2017;
- import javafx.util.Pair;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.LinkedHashMap;
- import java.util.Map;
- public class P04_PokemonEvolution {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String input = "";
- Map<String, ArrayList<Pair<String, Integer>>> map = new LinkedHashMap<>();
- String oneName = "";
- String pokemon = "";
- while (true) {
- input = reader.readLine();
- if (input.equals("wubbalubbadubdub")) break;
- String[] tokens = input.split(" -> ");
- if (tokens.length == 1) {
- oneName = tokens[0];
- } else {
- pokemon = tokens[0];
- String evoType = tokens[1];
- int evoIndex = Integer.parseInt(tokens[2]);
- if (!map.containsKey(pokemon)) {
- map.put(pokemon, new ArrayList<>());
- map.get(pokemon).add(new Pair<>(evoType, evoIndex));
- } else {
- map.get(pokemon).add(new Pair<>(evoType, evoIndex));
- }
- }
- if (map.containsKey(oneName)) {
- System.out.println("# " + oneName);
- map.get(oneName)
- .forEach((value) -> {
- System.out.printf("%s <-> %d%n", value.getKey(), value.getValue());
- });
- }
- }
- map.forEach((key, value) -> {
- System.out.printf("# %s%n", key);
- value.stream()
- .sorted((x1, x2) -> Integer.compare(x2.getValue(), x1.getValue()))
- .forEach(ordered -> {
- System.out.printf("%s <-> %d%n", ordered.getKey(), ordered.getValue());
- });
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment