English Number Translator

Interview

Time limit1sMemory limit128 MB

Summary
Parse English number words such as 'one thousand five hundred' into their integer value, handling negatives and an empty-line terminator.
Level

Medium4 of 10

Topics
String, Implementation, Math
Solved
No attempts yet

Problem

In this problem you are given one or more integers written out in English. Your task is to translate each number into its integer representation. The numbers range from -999,999,999 to 999,999,999. The following is the exhaustive list of English words your program must account for.

negative, 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

Input

The input consists of several instances, one per line. Notes on the input:

  1. Negative numbers are preceded by the word negative.
  2. The word hundred is not used when thousand could be used instead. For example, 1500 is written as one thousand five hundred, not fifteen hundred.

The input is terminated by an empty line.

Output

For each instance, print its integer value on its own line, with a newline after each answer.

Examples4

  1. Example 1

    Input
    six
    negative seven hundred twenty nine
    one million one hundred one
    eight hundred fourteen thousand twenty two
    
    Expected output
    6
    -729
    1000101
    814022
    
  2. Example 2

    Input
    zero
    
    
    Expected output
    0
    
  3. Example 3

    Input
    ten
    twenty
    thirty
    forty
    fifty
    sixty
    seventy
    eighty
    ninety
    
    Expected output
    10
    20
    30
    40
    50
    60
    70
    80
    90
    
  4. Example 4

    Input
    eleven
    twelve
    thirteen
    fourteen
    fifteen
    sixteen
    seventeen
    eighteen
    nineteen
    
    Expected output
    11
    12
    13
    14
    15
    16
    17
    18
    19