Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws IOException {
- BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
- TreeMap<String, LinkedHashMap<String, int[]>> map = new TreeMap<>();
- String input;
- while (!"end".equals(input = rd.readLine())) {
- String[] info = input.split(" ");
- String IP = info[0].split("=")[1];
- String user = info[2].split("=")[1];
- map.putIfAbsent(user, new LinkedHashMap<>());
- map.get(user).putIfAbsent(IP, new int[1]);
- map.get(user).get(IP)[0]++;
- }
- map.forEach((key, value) -> System.out.printf("%s: %n%s.%n", key, getIPs(value)));
- }
- private static String getIPs(LinkedHashMap<String, int[]> value) {
- return value.entrySet().stream().map(e -> String.format("%s => %d", e.getKey(), e.getValue()[0])).collect(Collectors.joining(", "));
- }
Add Comment
Please, Sign In to add comment