Problem Statement
Recently, your boss decided that all sales that your company makes should be in the form of "BUY X GET Y FREE", where X and Y are integers. For example, rather than advertising that your latest product is on sale for $4.00, when it normally sells for $6.00, he wants you to advertise it as a "BUY 2 GET 1 FREE" sale.
Given regular, the normal price of the item, and sale, the sale price of the item , return a String formatted as "BUY X GET Y FREE" (quotes for clarity only), where X and Y are positive integers with no leading zeroes. X and Y must be as small as possible (for example, return "BUY 2 GET 1 FREE" instead of "BUY 4 GET 2 FREE").
Definition
- Class:
- SalePitch
- Method:
- buyXGetY
- Parameters:
- String, String
- Returns:
- String
- Method signature:
- String buyXGetY(String regular, String sale)
- (be sure your method is public)
Constraints
- regular and sale will be formatted as "$X.YZ", where X represents an integer between 0 and 9999, inclusive, with no extra leading zeroes, and Y and Z are each between '0' and '9', inclusive.
- The value represented by sale will be less than that represented by regular.
- Neither regular nor sale will be "0.00".
Examples
"$6.00"
"$4.00"
Returns: "BUY 2 GET 1 FREE"
The example from the problem statement."$100.00"
"$0.50"
Returns: "BUY 1 GET 199 FREE"
"$12.34"
"$5.67"
Returns: "BUY 567 GET 667 FREE"
"$12.34"
"$8.64"
Returns: "BUY 432 GET 185 FREE"
"$9069.96"
"$4972.81"
Returns: "BUY 497281 GET 409715 FREE"
"$1000.00"
"$65.50"
Returns: "BUY 131 GET 1869 FREE"