#C871. Summary Report Generator
Summary Report Generator
Summary Report Generator
You are given a sequence of log entries, each containing a timestamp, an event type, and an event description. The log entries are provided line by line via standard input, and the input terminates with a line that contains only the string END
.
Your task is to generate a summary report for the events. The summary report should display, for each hour that contains at least one event, a line in the following format:
YYYY-MM-DD HH \(\texttt{}: , : , \ldots\)
Within each hourly group, the event types must be sorted in alphabetical order. If there are no events for an hour, that hour should be omitted from the report.
Note: When processing the time, only consider the hour portion (i.e. the first two characters of the time string).
Example:
Input: 2023-10-01 08:23:45 LOGIN User123 logged in 2023-10-01 08:47:12 LOGOUT User123 logged out 2023-10-01 09:00:01 LOGIN User456 logged in 2023-10-01 10:15:05 LOGIN User789 logged in 2023-10-01 10:45:30 LOGOUT User456 logged out 2023-10-02 08:00:00 LOGIN User123 logged in 2023-10-02 08:30:00 LOGOUT User123 logged out END</p>Output: 2023-10-01 08 LOGIN: 1, LOGOUT: 1 2023-10-01 09 LOGIN: 1 2023-10-01 10 LOGIN: 1, LOGOUT: 1 2023-10-02 08 LOGIN: 1, LOGOUT: 1
inputFormat
The input is provided via standard input and consists of multiple lines. Each line (except the last) represents a log entry with the following format:
YYYY-MM-DD HH:MM:SS EVENT_TYPE event_description
The final line of the input will be a line with exactly END
, which signals the end of the input.
outputFormat
The output should be printed to standard output. For each hour that has at least one event, print a line in the format:
YYYY-MM-DD HH EVENT_TYPE1: count1, EVENT_TYPE2: count2, ...
Within each hour, the event types must be sorted in alphabetical order. There should be no extra spaces at the end of the lines.
## sample2023-10-01 08:23:45 LOGIN User123 logged in
2023-10-01 08:47:12 LOGOUT User123 logged out
2023-10-01 09:00:01 LOGIN User456 logged in
2023-10-01 10:15:05 LOGIN User789 logged in
2023-10-01 10:45:30 LOGOUT User456 logged out
2023-10-02 08:00:00 LOGIN User123 logged in
2023-10-02 08:30:00 LOGOUT User123 logged out
END
2023-10-01 08 LOGIN: 1, LOGOUT: 1
2023-10-01 09 LOGIN: 1
2023-10-01 10 LOGIN: 1, LOGOUT: 1
2023-10-02 08 LOGIN: 1, LOGOUT: 1
</p>