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 hh:mm,xx 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. |
|
Definition |
|
Class: |
TimeCard |
Method: |
leave |
Parameters: |
String[] |
Returns: |
String |
Method signature: |
String leave(String[] time) |
(be sure your method is public) | |
|
|
|
Constraints |
- |
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. |
|
Examples |
0) |
|
|
|
Returns: "BELOW 40" |
This is my one and only shift, and I am only allowed to work 20 hours on a shift. | | |
1) |
|
|
{"09:00,am","05:00,pm","09:00,am","05:00,pm",
"09:00,am","05:00,pm","09:00,am","05:00,pm","09:00,am"} | |
Returns: "05:00,pm" |
I have worked 4 previous shifts of 8 hours, so I need 8 hours on this shift to make 40. | | |
2) |
|
|
{"12:00,am","08:00,pm","12:00,am","08:00,pm","12:00,am"} | |
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. | | |
3) |
|
|
{"12:00,pm","08:00,pm","12:00,am","08:00,pm","12:00,am"} | |
Returns: "12:00,pm" |
| |
4) |
|
|
{"09:00,am","04:31,pm","09:00,am","04:31,pm",
"09:00,am","05:00,pm","09:00,am","05:00,pm","03:53,am"} | |
Returns: "12:51,pm" |
| |
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2005, TopCoder, Inc. All rights reserved. |