veronikaaa86

SnowWhite11

Feb 22nd, 2018
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package exams.january2018;
  2.  
  3. import javafx.util.Pair;
  4.  
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10.  
  11. public class Demo {
  12.     public static void main(String[] args) throws IOException {
  13.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  14.  
  15.         Map<Pair<String, String>, Long> map = new HashMap<>();
  16.  
  17.         while (true) {
  18.             String input = reader.readLine();
  19.             if ("Once upon a time".equals(input)) break;
  20.  
  21.             String[] line = input.split("[\\s<:>]+");
  22.             String name = line[0];
  23.             String color = line[1];
  24.             long physics = Long.parseLong(line[2]);
  25.  
  26.             Pair<String, String> dwarf = new Pair<>(name, color);
  27.  
  28.             if (!map.containsKey(dwarf)) {
  29.                 map.put(dwarf, physics);
  30.             } else {
  31.                 long oldPhysics = map.get(dwarf);
  32.  
  33.                 if (physics > oldPhysics) {
  34.                     map.put(dwarf, physics);
  35.                 }
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment