#C14203. Log Parser

    ID: 43827 Type: Default 1000ms 256MiB

Log Parser

Log Parser

You are given a list of log entries along with two timestamps in the format YYYY-MM-DD HH:MM:SS. Each log entry is a string that may start with a timestamp enclosed in square brackets. Your task is to print out all log entries whose timestamp falls between the start and end timestamps (inclusive). Note that some log lines might be invalid or not follow the proper format. If the provided timestamps are in an incorrect format, output an error message. Also, if the start timestamp is later than the end timestamp, output an error message.

The error messages should be exactly:

  • Incorrect timestamp format, should be "$\text{YYYY-MM-DD HH:MM:SS}$"
  • Start timestamp must be earlier than end timestamp

Note: All formulas (if any) must use LaTeX formatting.

inputFormat

The input is read from stdin and has the following format:

N
log_entry_1
log_entry_2
...
log_entry_N
start_timestamp
end_timestamp

Where:

  • N is an integer representing the number of log entries.
  • Each log_entry is a string that may be a valid log (starting with a timestamp in square brackets) or an invalid line.
  • start_timestamp and end_timestamp are strings in the format YYYY-MM-DD HH:MM:SS.

outputFormat

The output should be printed to stdout and must follow one of these rules:

  • If the timestamps are not in the correct format, print:
    Incorrect timestamp format, should be "$\text{YYYY-MM-DD HH:MM:SS}$"
  • If the start timestamp is later than the end timestamp, print:
    Start timestamp must be earlier than end timestamp
  • Otherwise, print all valid log entries (in their original order) whose timestamp lies between the two given timestamps (inclusive). Each matching log entry should be printed on a new line. If there are no matching log entries, print nothing.
## sample
3
[2023-01-01 10:00:00] INFO Starting process
[2023-01-01 10:05:00] INFO Process running
[2023-01-01 10:10:00] ERROR Process failed
2023-01-01 10:00:00
2023-01-01 10:10:00
[2023-01-01 10:00:00] INFO Starting process

[2023-01-01 10:05:00] INFO Process running [2023-01-01 10:10:00] ERROR Process failed

</p>