Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exams.january2018;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.HashMap;
- import java.util.Map;
- public class P04_SnowWhite {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- Map<String, HashMap<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]);
- if (!map.containsKey(name)) {
- map.put(name, new HashMap<>());
- }
- if (!map.get(name).containsKey(color)) {
- map.get(name).put(color, 0L);
- }
- long current = 0;
- if (map.get(name).containsKey(color)) {
- current = map.get(name).get(color);
- if (current < physics) {
- map.get(name).put(color, physics);
- }
- }
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment