TopCoder problem "SalePitch" used in TCHS SRM 19 (Division I Level Two)



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

0)
    
"$6.00"
"$4.00"
Returns: "BUY 2 GET 1 FREE"
The example from the problem statement.
1)
    
"$100.00"
"$0.50"
Returns: "BUY 1 GET 199 FREE"
2)
    
"$12.34"
"$5.67"
Returns: "BUY 567 GET 667 FREE"
3)
    
"$12.34"
"$8.64"
Returns: "BUY 432 GET 185 FREE"
4)
    
"$9069.96"
"$4972.81"
Returns: "BUY 497281 GET 409715 FREE"
5)
    
"$1000.00"
"$65.50"
Returns: "BUY 131 GET 1869 FREE"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6825

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10071&pm=6825

Writer:

connect4

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Math