English Number Translator
InterviewTime limit1sMemory limit128 MB
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:
- Negative numbers are preceded by the word
negative. - The word
hundredis not used whenthousandcould be used instead. For example, 1500 is written asone thousand five hundred, notfifteen 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.