#K54317. Log Filtering by Time Range and Keyword
Log Filtering by Time Range and Keyword
Log Filtering by Time Range and Keyword
You are given a series of log entries, each containing a timestamp and a message.
Your task is to filter these logs to only include those whose timestamp falls within a specific time range and whose message contains a given keyword. The timestamps are provided in the YYYY-MM-DD HH:MM:SS format and can be compared lexicographically.
More formally, let \(T\) denote the timestamp of a log entry. You must select all entries such that \[ start\_time \leq T \leq end\_time \] and the log message contains the given keyword as a substring.
The filtered log entries should be printed in chronological order. Each log entry should be printed on a separate line in the format:
timestamp, message
If no log entry satisfies the conditions, the program should output nothing.
inputFormat
The input is read from standard input (stdin) in the following format:
- An integer \(N\) representing the number of log entries.
- Next \(N\) lines: each line represents a log entry in the format
timestamp, message
(the timestamp and message are separated by a comma and a space). - A line containing the \(start\_time\) (in the format
YYYY-MM-DD HH:MM:SS
). - A line containing the \(end\_time\) (in the format
YYYY-MM-DD HH:MM:SS
). - A line containing the
keyword
to filter log messages.
You can assume that the timestamp in each log entry is valid and that the logs (if any) are not necessarily sorted.
outputFormat
Print to standard output (stdout) the filtered log entries in chronological order. Each matching log entry should be printed on a separate line in the format:
timestamp, message
If no log entry meets the criteria, do not print anything.
## sample1
2023-10-01 10:00:00, System started
2023-10-01 09:00:00
2023-10-01 11:00:00
System
2023-10-01 10:00:00, System started