TopCoder problem "TimeCard" used in SRM 257 (Division II Level Three)

Problem Statement

    When I start my shift at work I punch in my starting time, and when I leave I punch out. The times are printed on a card using exactly 8 characters in the format
where hh is the 2 digit representation of the hour, mm is the 2 digit representation of the minute, and xx is either am or pm. The ':' and ',' are literal. "12:00,am" denotes midnight, while "12:00,pm" denotes noon.

The difference between that time I punch in and the time I punch out is the amount of time I have worked so, for example, if I punch in at 03:33pm and punch out at 03:34pm I have worked 1 minute.

No shift is allowed to be more than 20 hours long. This is my last shift of the week and I am supposed to work 40 hours during the week. Create a class TimeCard that contains a method leave that is given a String[] time of all the times on this week's timecard and that returns a String (using the same format) that tells when I can leave and have exactly 40 hours for the week. Return "BELOW 40" or "ABOVE 40" if it is not possible to get exactly 40 hours. In all cases, the return should contain exactly 8 characters.

The elements of time alternate: punch in time, punch out time, punch in time, ... with the final element being the time I just punched in on my final shift.



Method signature:String leave(String[] time)
(be sure your method is public)


-time will contain an odd number of elements between 1 and 49 inclusive.
-Each element of time will be formatted as above.
-In each element of time hh will be between 01 and 12 inclusive.
-In each element of time mm will be between 00 and 59 inclusive.
-time will contain no shift that exceeds 20 hours in duration.


Returns: "BELOW 40"
This is my one and only shift, and I am only allowed to work 20 hours on a shift.
Returns: "05:00,pm"
I have worked 4 previous shifts of 8 hours, so I need 8 hours on this shift to make 40.
Returns: "12:00,am"
I have already worked 2 shifts of 20 hours so I already have exactly 40 hours. I should go home immediately.
Returns: "12:00,pm"
Returns: "12:51,pm"

Problem url:

Problem stats url:




PabloGilberto , lbackstrom , brett1479 , Olexiy

Problem categories:

Simple Math, String Manipulation