Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exams.january2018;
- import javafx.util.Pair;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.HashMap;
- import java.util.Map;
- public class Demo {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- Map<Pair<String, String>, Long> map = new HashMap<>();
- while (true) {
- String input = reader.readLine();
- if ("Once upon a time".equals(input)) break;
- String[] line = input.split("[\\s<:>]+");
- String name = line[0];
- String color = line[1];
- long physics = Long.parseLong(line[2]);
- Pair<String, String> dwarf = new Pair<>(name, color);
- if (!map.containsKey(dwarf)) {
- map.put(dwarf, physics);
- } else {
- long oldPhysics = map.get(dwarf);
- if (physics > oldPhysics) {
- map.put(dwarf, physics);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment