TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

RoboParking

Problem statement, definition, constraints, and public examples.

Problem Statement

You are to write permit-validation software for a parking lot that operates without human attendants. Before an automobile enters the lot, it must pull up to a permit dispenser. Here, the driver uses a credit card to purchase a fixed amount of parking time, after which she may proceed into the lot. Later in the day, when the driver retrieves her car and is on the way out, she must pause at a barrier to swipe her credit card. If she has exceeded her prepaid parking time, a surcharge is calculated and applied to her credit card. Drivers have a strong incentive to leave on time, since the prepaid parking rate is $1.00 an hour, but the surcharge rate is $0.10 a minute.

You are given a String[] named permitPurchases, each element of which describes one parking permit in the following format.


  <TIME_ISSUED> <AMOUNT_PAID>

The <TIME_ISSUED> field is given in the format


  <HOUR>:<MINUTE><TIME_OF_DAY>

where <HOUR> is a non-zero-padded integer between 1 and 12, inclusive; <MINUTE> is a two-digit, zero-padded integer between 00 and 59, inclusive; and <TIME_OF_DAY> is either "am" or "pm".

The <AMOUNT_PAID> field of the permit description is in the format


$<DOLLARS>.<CENTS>

where <DOLLARS> is either 0 or a non-zero-padded positive integer, and <CENTS> is a two-digit, zero-padded integer. The prepaid value of each permit is between $0.25 and $24.00, inclusive. Since parking time is purchased in quarter-hour increments, the number of cents must be divisible by 25. There are no spaces in the permit description except for a single space separating the <TIME_ISSUED> and <AMOUNT_PAID> fields.

You are also given a String[] named exitStamps, each element of which represents the time at which the corresponding automobile exited. In other words, the kth element of exitStamps contains the exit time of the car whose permit is described by the kth element of permitPurchases. Each element of exitStamps is given in the same format as the <TIME_ISSUED> field defined above.

Each car arrives and departs between the times 12:00am and 11:59pm, inclusive. The time at which a car departs cannot be earlier than the time at which it arrived. Given that a driver is charged $0.10 for each minute in excess of her prepaid parking time, calculate the surcharge for each car and represent it in the same format as the <AMOUNT_PAID> field defined above. The difference is that here, the number of cents will necessarily be divisible by 10, and the surcharge may well exceed $24.00. If a car has left within its prepaid parking time, the surcharge is $0.00. Return all surcharges in a String[], the kth element of which corresponds to the kth parking permit.

Definition

Class:
RoboParking
Method:
computeSurcharges
Parameters:
String[], String[]
Returns:
String[]
Method signature:
String[] computeSurcharges(String[] permitPurchases, String[] exitTimes)
(be sure your method is public)

Constraints

  • permitPurchases contains between 1 and 50 elements, inclusive
  • exitStamps contains the same number of elements as permitPurchases
  • each element of permitPurchases adheres to the format described above
  • each element of exitStamps adheres to the format described above

Examples

  1. {"11:50am $2.00", "11:30am $2.00"}
    
    {"1:50pm", "1:50pm"}
    Returns: { "$0.00",  "$2.00" }
    One driver enters at 11:50am and pays for 2 hours of parking time. Exactly 2 hours later, he departs without a surcharge. Another driver enters at 11:30am and pays for 2 hours as well, but leaves 2 hours and 20 minutes later. This is 20 minutes over his prepaid time, so he incurs a surcharge of 20*$0.10 = $2.00.
  2. {"9:45am $0.25", "9:45am $0.25"}
    {"9:45am", "9:45pm"}
    Returns: { "$0.00",  "$70.50" }
    One driver enters, pays for 15 minutes, and immediately departs. Another driver enters and stays for 12 hours or 720 minutes, of which she has paid for only 15 minutes, so she must pay for the additional 705.
  3. {"9:17am $3.75", "9:17am $8.25"}
    
    {"3:02pm", "3:02pm"}
    Returns: { "$12.00",  "$0.00" }
    Two drivers enter at 9:17am and leave at 3:02pm. One paid for 120 minutes fewer than he ended up staying. The other paid for the entire length of his stay.
  4. {"12:00am $23.75", "11:44am $0.25"}
    {"11:55pm", "12:00pm"}
    Returns: { "$1.00",  "$0.10" }
    One driver overstays her permit by 10 minutes, the other by 1 minute.
  5. {"3:27am $15.00", "2:01am $2.75", "3:30pm $4.75", "2:10pm $0.25",
     "4:50am $1.00", "12:02am $19.00", "10:12am $2.75", "6:57am $0.75"}
    {"9:18pm", "12:14pm", "8:04pm", "2:19pm",
     "3:29pm", "11:11am", "4:19pm", "9:05pm"}
    Returns: { "$17.10",  "$44.80",  "$0.00",  "$0.00",  "$57.90",  "$0.00",  "$20.20",  "$80.30" }
Back to all problems