Talking Money
Time limit2sMemory limit256 MB
Convert one currency amount from -$999999999999.99 to $999999999999.99 into English words under the given hyphen, and-placement, and plural rules.
- Level
Medium4 of 10
- Topics
- Implementation, String
- Solved
- No attempts yet
Problem
A telephone banking system reads account balances out loud to customers. The text to speech engine behind it cannot pronounce numbers, so every amount has to reach it already written out in English words.
Convert one currency value between -$999999999999.99 and $999999999999.99 to words. None of the bank customers are trillionaires just yet.
Both parts of the amount are always written, so a dollar amount of 0 becomes zero dollars and a cent amount of 0 becomes zero cents. The following rules apply.
- A billions, millions, thousands, or units group whose value is 0 is not written at all.
- Every number from 21 to 99 that is not a multiple of ten joins its tens word and its units word with a single hyphen, for example
twenty-oneandninety-nine. - The word
andfollows the wordhundredin every case except a round hundred. Compareone hundred thousandwithone hundred and twenty-three thousand. - The word
andgoes between the smallest written group among billions, millions and thousands and the units group when the units group is less than one hundred and is not 0. Comparetwo thousand and forty-sixwithtwo thousand five hundred and fifty-seven. - The word
dollarsfollows the dollar amount, except when the dollar amount is exactly 1, where the word isdollar. - The word
andgoes between the dollar amount and the cent amount. - The word
centsfollows the cent amount, except when the cent amount is exactly 1, where the word iscent. - A negative value ends with
in debit, and a positive value ends within credit. - A value of zero ends with neither
in debitnorin credit.
The only spellings needed are zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety, hundred, thousand, million, billion.
Input
The first line holds the value v, written as a minus sign for a negative value, then $, then the dollar amount with no digit separators, then ., then exactly two digits for the cents.
The dollar amount has no leading zero unless it is 0. The value satisfies -999999999999.99 ≤ v ≤ 999999999999.99, and a value of zero is given as $0.00 with no minus sign.
Output
Print the amount in English words on one line, with a single space between words.