#K13571. Building Entry Swipe Time Calculation
Building Entry Swipe Time Calculation
Building Entry Swipe Time Calculation
You are given a set of swipe records for a building entrance. Each record consists of a timestamp in 24-hour format (HH:MM) and a swipe action which is either 'E' (enter) or 'X' (exit). The records may not be in order; you must sort them by time and then verify that the sequence is valid.
A valid sequence must alternate between an entry and an exit. If an entry occurs before a previous session has ended or an exit occurs without a corresponding entry, then the sequence is considered invalid. If the sequence is valid, compute the total time spent inside the building and output the result in HH:MM format. In the event of an invalid sequence, output Error: Invalid swipe order. In the case of no records, assume the total time is 00:00.
The time difference between two timestamps is computed as the difference between exit time and the most recent entry time.
Note: All formulas are rendered in \( \LaTeX \) format. For example, if the time difference in minutes is computed as \( \Delta t = t_{\text{exit}} - t_{\text{entry}} \), then the total time is the sum of all such durations.
inputFormat
The input is read from stdin and is formatted as follows:
- The first line contains an integer \( n \) denoting the number of swipe records.
- The following \( n \) lines each contain a timestamp and an action separated by a space. The timestamp is in the format HH:MM and the action is either 'E' or 'X'.
If \( n = 0 \), there are no records and the total time should be considered as "00:00".
outputFormat
Output the result to stdout as a single line. If the sequence is valid, print the total time spent inside the building in HH:MM format. Otherwise, print Error: Invalid swipe order.
## sample4
09:00 E
12:30 X
13:15 E
17:45 X
08:00