View difference between Paste ID: h0160YLQ and bdzA4B1q
SHOW: | | - or go back to the newest paste.
1
public static void main(String[] args) throws IOException {
2
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
3
4
        TreeMap<String, LinkedHashMap<String, int[]>> map = new TreeMap<>();
5
        String input;
6
7
        while (!"end".equals(input = rd.readLine())) {
8
            String[] info = input.split(" ");
9
            String IP = info[0].split("=")[1];
10
            String user = info[2].split("=")[1];
11
12
            map.putIfAbsent(user, new LinkedHashMap<>());
13
            map.get(user).putIfAbsent(IP, new int[1]);
14
            map.get(user).get(IP)[0]++;
15
        }
16
17
        map.forEach((key, value) -> System.out.printf("%s: %n%s.%n", key, getIPs(value)));
18
    }
19
20
    private static String getIPs(LinkedHashMap<String, int[]> value) {
21
        return value.entrySet().stream().map(e -> String.format("%s => %d", e.getKey(), e.getValue()[0])).collect(Collectors.joining(", "));
22
    }