Advertisement
ivanov_ivan

PokeMon Evo - Java

Nov 3rd, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.*;
  5.  
  6. public class PokemonEvo {
  7.     public static void main(String[] args) throws IOException {
  8.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  9.  
  10.         Map<String, List<String>> inputMap = new LinkedHashMap<>();
  11.  
  12.         String input;
  13.  
  14.         while (!"wubbalubbadubdub".equals((input = reader.readLine()))) {
  15.             String[] tokens = input.split(" -> ");
  16.  
  17.             if (tokens.length > 1) {
  18.                 inputMap.putIfAbsent(tokens[0],new ArrayList<>());
  19.                 String str = tokens[1] + " <-> " + tokens[2];
  20.                 inputMap.get(tokens[0]).add(str);
  21.             } else if (inputMap.containsKey(tokens[0])){
  22.                 System.out.println("# " + tokens[0]);
  23.                 inputMap.get(tokens[0])
  24.                         .forEach(System.out::println);
  25.             }
  26.         }
  27.         inputMap.forEach((key,value) -> {
  28.             System.out.println("# " + key);
  29.  
  30.             value.stream().sorted((first,second) -> {
  31.                 String firstNumAsString = first.split(" <-> ")[1];
  32.                 int firstNum = Integer.parseInt(firstNumAsString);
  33.  
  34.                 String secondNumAsString = second.split(" <-> ")[1];
  35.                 int secondNum = Integer.parseInt(secondNumAsString);
  36.  
  37.                 return Integer.compare(secondNum,firstNum);
  38.  
  39.             }).forEach(System.out::println);
  40.         });
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement