Before an interstellar hauler can undock, its cargo manifest — one line of space-separated tokens — must be updated to reflect a dock-authorized markdown. A token is a credit amount if and only if it consists of exactly one '$' character followed by one or more digits and nothing else, where the digit sequence has no leading zero unless the digit sequence is exactly "0" (so "$0" and "$40" are credit amounts, while "$", "$07", "$4a", and "a$4" are not — those are ordinary cargo labels).
Given the discount percentage authorized by dock control, replace every credit-amount token "$X" with "$" followed by the discounted value of X, computed exactly as X * (100 - discount) / 100 and printed with exactly two digits after the decimal point. Every token that is not a credit amount must be copied through completely unchanged. Tokens keep their original order and stay separated by single spaces in the output, exactly as in the input.
Line 1: an integer discount (0 <= discount <= 100) — the percentage markdown authorized for this manifest.
Line 2: the manifest — a single line of tokens separated by single spaces, with no leading or trailing spaces.
Print one line: the manifest with every credit-amount token replaced by its discounted value as described above, and every other token unchanged, in the original order, separated by single spaces.
0 <= discount <= 1001 <= number of tokens in the manifest <= 1001 <= length of each token <= 20'a'-'z'), digits ('0'-'9'), and the character '$'."$X", the digit sequence X has at most 10 digits and its value is at most 10^9.Example 1
Input
50 load $200 crate7 $75 seal99
Expected
load $100.00 crate7 $37.50 seal99
Explanation
discount=50%. "load", "crate7", and "seal99" are not credit amounts and are unchanged. "$200" -> 200 * 50 / 100 = 100.00 -> "$100.00". "$75" -> 75 * 50 / 100 = 37.50 -> "$37.50". Result: "load $100.00 crate7 $37.50 seal99".
Example 2
Input
0 manifest $0 $07 $5
Expected
manifest $0.00 $07 $5.00
Explanation
discount=0%, so credit amounts keep their value but are still reformatted to two decimals. "manifest" is unchanged. "$0" is a valid credit amount (the single digit "0" has no leading-zero violation) -> "$0.00". "$07" has a leading zero on a multi-digit sequence, so it is NOT a credit amount and stays exactly "$07". "$5" -> "$5.00". Result: "manifest $0.00 $07 $5.00".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →