TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

ParkBot

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> <MINUTES_PURCHASED>

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 <MINUTES_PURCHASED> field of the permit description is a non-zero-padded integer between 15 and 1440, inclusive, indicating the number of parking minutes purchased for the car. Since parking time is purchased in quarter-hour increments, this number must be divisible by 15. There are no spaces in the permit description except for a single space separating the <TIME_ISSUED> and <MINUTES_PURCHASED> 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 with a String in the format


  $<DOLLARS>.<CENTS>

where <DOLLARS> is either 0 or a non-zero-padded positive integer, and <CENTS> is a zero-padded integer of exactly two digits. 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:
ParkBot
Method:
computeSurcharges
Parameters:
String[], String[]
Returns:
String[]
Method signature:
String[] computeSurcharges(String[] permitPurchases, String[] exitStamps)
(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 120", "11:30am 120"}
    {"1:50pm", "1:50pm"}
    Returns: { "$0.00",  "$2.00" }
    One driver enters at 11:50am and pays for 120 minutes, or 2 hours, of parking time. Exactly 2 hours later, he departs without a surcharge. Another driver enters at 11:30am and pays for 120 minutes as well, but he leaves 140 minutes later. This is 20 minutes over his prepaid time, so he incurs a surcharge of 20*$0.10 = $2.00.
  2. {"9:45am 15", "9:45am 15"}
    {"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 225", "9:17am 345"}
    {"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 1425", "11:44am 15"}
    {"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 900", "2:01am 165", "3:30pm 285", "2:10pm 15",
     "4:50am 60", "12:02am 1140", "10:12am 165", "6:57am 45"}
    {"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