Cheque Writing -- Problem R (50 points)


Most firms write so many cheques that they have special cheque form stationery for the printer and a program which writes details on the cheque forms. It is legally required that the amount of the cheque has to appear in both numbers and words. Thus a program is needed which will write amounts as words. The rules for doing this for whole numbers are as follows:

1. Remove any leading zeroes then divide the number into 3-digit groups starting from the right. If the leftmost group has fewer than 3 digits then add leading zeroes and regard it as a normal 3-digit group.

2. Write the name of the leftmost 3-digit group (see point 4.) followed by the word "billion", "million", "thousand" or "" (nothing) as appropriate - the appropriate word can be found from the size as follows: bbb,mmm,ttt,nnn where bbb = 3-digit group which is followed by billion, etc (nnn corresponds to "").

3. If the remainder of the number is 0 then this is the end of the name, otherwise write a comma, eliminate the leftmost 3-digit group, and continue at step 2 with the new leftmost 3-digit group.

4. To get the name of a 3-digit group: if the leftmost digit is non-zero then write its name ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine"), followed by "hundred". This is followed by "and" then the name of the two-digit number after the hundreds digit, unless this 2-digit number is 0 in which case nothing more is written.

5. The name of a non-zero two-digit number is found as follows: if the tens digit is zero then it's the name of the units digit; if the tens digit is 1 then the name is one of "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"; if the tens digit is 2 or more then the name is one of "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", followed by the name of the units digit, unless the units digit is 0 in which case nothing more is written.

6. There is a single space character after each word written, except for words followed by a comma when the comma comes immediately after the word and is followed by a single space.

For amounts of 1 dollar or more, the name of the whole dollar amount should be written, followed by the word "dollars" (or "dollar" if the dollar amount is 1). If the cents value is 0 then this is followed by the word "only" otherwise the name of the 2-digit cents amount(see point 5) followed by "cents". If the amount is less than one dollar then the words "no dollars" should be written, followed by the name of the cents amount and the word "cents" (you may assume a cheque for $0.00 or less will never be written). Thus $12345.67 is written as "twelve thousand, three hundred and forty five dollars sixty seven cents" and $1000001.01 is written as "one million, one dollars one cents"

Input will be from a file called PROBLEM3.DAT and will consist of decimal numbers to two decimal places, one per line. Each number will be bigger than 0.00 and less than 2,100,000,000.00. The file will be terminated by a line containing a single 0.

Output, which must be written to standard output (the screen), must be the word version of the corresponding number, regarded as an amount in dollars and cents.

Example Input

12345.67
1000001.01
0

Example Output

twelve thousand, three hundred and forty five dollars sixty seven cents
one million, one dollar one cents