#K67492. Calculate Work Hours
Calculate Work Hours
Calculate Work Hours
In this problem, each employee at a company records their working times by clocking in and clocking out. You are given a sequence of events, where each event is represented by a line in the format <employee_id> <action> <time>
. The action
is either clockin
or clockout
, and the time
is provided in the 24-hour clock format (HH:MM
). The input ends with a line containing the word end
.
Your task is to compute the total working hours for each employee. For every valid clock-in followed by a corresponding clock-out, the time difference in minutes is computed and then summed. The working hours for an interval where an employee clocks in at time \(t_1\) and clocks out at time \(t_2\) is given by \[ \frac{t_2 - t_1}{60} \] If an employee clocks in without a subsequent clock-out before the end of input, that incomplete interval should be ignored (i.e. it contributes 0 hours).
Output the result as one line per employee: each line should contain the employee id and the total hours worked, rounded to two decimal places, ordered by employee id in ascending order.
inputFormat
The input is read from stdin
and consists of several lines. Each line (except the last) represents an event record in the format:
<employee_id> <action> <time>
The input terminates with a line containing exactly end
.
outputFormat
For each employee who appears in the input, output a single line to stdout
containing the employee id and the total number of working hours for that day formatted to two decimal places. The results should be printed in increasing order of employee id.
1 clockin 08:00
1 clockout 12:00
end
1 4.00
</p>