#C6912. Log Parsing Challenge

    ID: 50725 Type: Default 1000ms 256MiB

Log Parsing Challenge

Log Parsing Challenge

You are given a number of log entries. Each log entry is a string starting with an IP address followed by additional data. Your task is to determine:

  1. The total number of log entries, ( n ).
  2. The total number of unique IP addresses present in the logs.
  3. A dictionary mapping each unique IP address to the number of times it appears.

Input Format: The first line of input contains an integer ( n ), denoting the number of log entries. The following ( n ) lines each contain one log entry. The IP address is always the first token in each log entry, where tokens are delimited by whitespace.

Output Format: Print three lines: the total number of log entries, the number of unique IP addresses, and the dictionary (in JSON format) mapping each IP address to its count. In the dictionary, the IP addresses must be sorted in ascending order.

Example:
If the input is:

3
192.168.1.1 - - [10/Oct/2020:13:55:36 -0700] "GET /index.html HTTP/1.1" 200 2326
192.168.1.2 - - [10/Oct/2020:13:58:36 -0700] "POST /form HTTP/1.1" 200 124
192.168.1.1 - - [10/Oct/2020:14:12:21 -0700] "GET /contact.html HTTP/1.1" 404 721

The output should be:

3
2
{"192.168.1.1": 2, "192.168.1.2": 1}

inputFormat

The first line contains an integer ( n ) which represents the number of log entries. This is followed by ( n ) lines, each line containing a single log entry. Each log entry begins with the IP address.

outputFormat

The output consists of three lines:

  1. Total number of log entries (integer).
  2. Number of unique IP addresses (integer).
  3. A JSON formatted dictionary mapping each IP address to its occurrence count. The keys in the dictionary should be sorted in ascending order.## sample
3
192.168.1.1 - - [10/Oct/2020:13:55:36 -0700] "GET /index.html HTTP/1.1" 200 2326
192.168.1.2 - - [10/Oct/2020:13:58:36 -0700] "POST /form HTTP/1.1" 200 124
192.168.1.1 - - [10/Oct/2020:14:12:21 -0700] "GET /contact.html HTTP/1.1" 404 721
3

2 {"192.168.1.1": 2, "192.168.1.2": 1}

</p>