Your task is to convert Chinese numerals into Arabic numerals.
A problem similar to Convert Chinese numbers, however, more complex. Also, answers given there mostly don't satisfy all the conditions.
Chinese digits/numbers are as follows:
Multiple-digit numbers are created by adding from highest to lowest and by multiplying from lowest to highest. In case of additions, each number higher than 9 can be multiplied by 1 and it won't change its meaning. Both
一亿一万一千一百一十一 are equal to
We multiply in the following fashion:
五千 = 5000
一百万 = 1000000
三千万 = 30000000.
Chinese always takes the lowest possible multiplier (just like we don't say hundred hundred but ten thousand). So
百千 doesn't exist to represent
100000 since we have
十千 doesn't exist since we have
十千万 doesn't exist, since we have
十百 doesn't exist, since we have
0 is very important and it was actually the biggest problem in the other code golf question. Trailing zeroes are omitted in Chinese, so
零 indicates interior zeroes.
Let's look at some examples:
三百零五 = 305
三百五 = 350- no interior zeroes. You can notice that we don't need
十here, since a trailing zero is omitted.
一千万零一百 = 10000100
三千零四万 = 30040000
六亿零四百零二 = 600000402- here we have 2 interior zeroes. As you can see though, even if there's a gap of more than one order of magnitute (in the example it's
零scan't stand next to each other, one is enough for each gap, no matter how big it is.
一亿零一 = 100000001- again, no need for more than one
零if there's one gap, no matter how big.
八千万九千 = 80009000- no need for
零since there are no interior zeroes. Why are there no interior zeroes? Because it follows the highest-to-lowest addition without omitting an order of magnitude. Right after
九is a multiplication component, not addition one) and not, let's say,
More examples: Check out the two "示例" paragraphs
2 is also special in Chinese as it can be represented with a character
两 if it's a multiplier of 100 and higher numerals. Both
Constraints: 0 <= N < 10^9
Edit: I don't care what happens from
10^9 onwards. Input doesn't have any examples equal or higher than
10^9 for that reason.
一亿两千三百零二万四千二百零三 四千万零一十 三十四万五千五 四亿二十万零九百零一 两千万九千零一十 二十四万零二百二十二 两千零十二 零
123024203 40000010 345500 400200901 20009010 240222 2012 0