#K52027. Employee Work Hours Monitoring
Employee Work Hours Monitoring
Employee Work Hours Monitoring
A company wants to implement a system to monitor its employees' check-in and check-out times to ensure compliance with working hours. Each employee uses a unique identification number, and may check in and out multiple times a day. The system should process three types of commands:
LOG_IN employee_id day time
: Record the check-in time (in minutes since midnight) for an employee on a given day.LOG_OUT employee_id day time
: Record the check-out time (in minutes since midnight) for an employee on a given day.QUERY employee_id day
: Calculate the total minutes worked by the employee on that day. Only complete check-in and check-out pairs (in order) should be counted. If there is an unmatched check-in or check-out, it is ignored.
For each QUERY
command, output the total working minutes accumulated by properly pairing the check-ins with corresponding check-outs (i.e. pairing in their order of occurrence). If there are no valid pairs, return 0.
Note: All times are provided in minutes since midnight and days are represented as non-negative integers starting from 0.
Below is an example:
Input: 8 LOG_IN 101 0 540 LOG_OUT 101 0 600 LOG_IN 101 0 660 LOG_OUT 101 0 720 QUERY 101 0 LOG_IN 102 1 480 LOG_OUT 102 1 1020 QUERY 102 1</p>Output: 120 540
inputFormat
The first line contains an integer n
representing the number of log entries. The following n
lines each contain one of the three commands:
LOG_IN employee_id day time
LOG_OUT employee_id day time
QUERY employee_id day
Here, employee_id
, day
, and time
are integers. time
is given in minutes since midnight.
outputFormat
For each QUERY
command in the order they appear, output a line containing the total number of minutes worked by that employee on the specified day. Each result should be printed on a new line.
8
LOG_IN 101 0 540
LOG_OUT 101 0 600
LOG_IN 101 0 660
LOG_OUT 101 0 720
QUERY 101 0
LOG_IN 102 1 480
LOG_OUT 102 1 1020
QUERY 102 1
120
540
</p>