Under construction

Still being built. Things may change

Talking About Numbers

Interview

Time limit1sMemory limit1024 MB

Summary
Given non-negative integers up to 999,999,999, print each one in English words, following the rules for hyphens, commas, and "and".
Level

Easy3 of 10

Topics
String, Math, Implementation
Solved
No attempts yet

Problem

The programmers of a TTS (text-to-speech) program found that their product reads numbers poorly. It announces each digit in turn, so the listener loses track after a few digits.

They want a more natural reading. One of them suggested converting numeric strings into English text, for example turning "10231023" into "one thousand and twenty three", so the speech engine can read the result with no further changes.

Write a program that converts non-negative integers into conventional English wording.

  • The numbers 00 to 1919 have unique names: "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen".
  • The following multiples of 1010 are "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety".
  • A multiple of ten combined with a digit 11 to 99 is hyphenated, for example 31⇒31 \Rightarrow "thirty-one" and 77⇒77 \Rightarrow "seventy-seven".
  • Multiples of 100100 use the digit name followed by "hundred", and any non-zero remainder after them is joined with "and", for example 200⇒200 \Rightarrow "two hundred", 412⇒412 \Rightarrow "four hundred and twelve", and 777⇒777 \Rightarrow "seven hundred and seventy-seven".
  • Thousands and millions are named with the rules above for numbers 11 to 999999. A non-zero remainder after them is separated by a comma, for example 1 253 101⇒1\,253\,101 \Rightarrow "one million, two hundred and fifty-three thousand, one hundred and one".
  • If a number with a non-empty thousands or millions part is followed by a remainder of 11 to 9999, the parts are joined with "and" instead of a comma, for example 1 000 011⇒1\,000\,011 \Rightarrow "one million and eleven" and 20 222 043⇒20\,222\,043 \Rightarrow "twenty million, two hundred and twenty-two thousand and forty-three".

Input

The input has one or more datasets. Each dataset is one line containing a non-negative integer from 00 to 999 999 999999\,999\,999. The input has no commas, and positive numbers have no leading zeros.

A line with a negative value ends the input.

Output

For each dataset, print the spelled-out number on its own line.

The output must be left-justified and all letters are lowercase. Exactly one blank separates adjacent words, except around a hyphen or comma. A comma is followed by exactly one blank. A hyphen has no blank on either side.

Examples1

  1. Example 1

    Input
    1
    222143
    1000001
    -1
    
    Expected output
    one
    two hundred and twenty-two thousand, one hundred and forty-three
    one million and one