Chinese/Japanese numbers to Arabic numerals

In Chinese and Japanese, here are the numbers one to ten next to the equivelant number:

1一
2二
3三
4四
5五
6六
7七
8八
9九
10十

They are also written in a different way to Arabic numerals:

三十 (three, ten) = 30
四十七 (four, ten, seven) = 47

As you can see, they're written in order from biggest to smallest, except when a number under 10 is used to multiply another number.

Your task is to convent any number under 99 from Chinese/Japanese format to Arabic format.

IN

三十

OUT

30

IN

四十七

OUT

47

IN

六十三

OUT

63

IN

三十八

OUT

28

IN

八十九

OUT

89
Login to submit solution


109 symbols haskell failed test 4 Wrong answer
38
instead of
28
Fri Jul 3 11:52:49 2015 YoshikuniJujo
import Data.List
main=interact$show.i
j=head.(`elemIndices`"零一二三四五六七八九十")
i(e:_:f)=j e*10+i f
i e=sum$j`map`e
85 symbols python2 failed test 1 Code error

File "./code", line 1 SyntaxError: Non-ASCII character '\xe5' in file ./code on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Thu Oct 8 14:15:42 2015 BogdanShevchenko
a='十一二三四五六七八九'
s=raw_input()
I=a.index(s[0])
print(I,I*10,I*10+a.index(s[2]))[len(s)]
87 symbols python3 failed test 1 Code error

Traceback (most recent call last): File "./code", line 2, in <module> s=raw_input() NameError: name 'raw_input' is not defined

Thu Oct 8 14:18:06 2015 BogdanShevchenko
a='十一二三四五六七八九'
s=raw_input()
I=a.index(s[0])
print((I,I*10,I*10+a.index(s[2]))[len(s)])
83 symbols python3 failed test 1 Code error

Traceback (most recent call last): File "./code", line 4, in <module> print((I,I*10,I*10+a.index(s[2]))[len(s)]) IndexError: string index out of range

Thu Oct 8 14:18:50 2015 BogdanShevchenko
a='十一二三四五六七八九'
s=input()
I=a.index(s[0])
print((I,I*10,I*10+a.index(s[2]))[len(s)])
86 symbols python3 failed test 4 Wrong answer
38
instead of
28
Thu Oct 8 14:59:31 2015 BogdanShevchenko
a='十一二三四五六七八九'
s=input()
I=a.index(s[0])
print((I,I*10,I*10+a.index(s[-1]))[len(s)-1])
77 symbols bash failed test 3 Wrong answer
630
instead of
63
Mon Jul 25 05:25:27 2016 hidefromkgb
c='\211\255\203\253\235';tr -dc $c|tr $c 36789|sed 's/7/47/;s/38/28/;s/3/30/'
31 symbols pyth failed test 1 Wrong answer
-11
instead of
30
Sat Oct 15 15:34:39 2016 Sait2000
+*T-xJ"十一二三四五六七八九"hzqz"三十八"xJez
37 symbols pyth failed test 1 Code error

Traceback (most recent call last): File "/usr/bin/pyth.py", line 713, in <module> exec(py_code_line, environment) File "<string>", line 2, in <module> File "/usr/bin/macros.py", line 668, in head return a[0] IndexError: string index out of range

Fri Oct 21 18:29:17 2016 Sait2000
+*T-xJ@tt"十一二三四五六七八九"3httzqz"三十八"xJez
49 symbols pyth failed test 1 Code error

Traceback (most recent call last): File "/usr/bin/pyth.py", line 713, in <module> exec(py_code_line, environment) File "<string>", line 2, in <module> File "/usr/bin/macros.py", line 241, in mod return a % b TypeError: not all arguments converted during string formatting

Fri Oct 21 18:32:34 2016 Sait2000
+*T-xJm%Cd64%tt"十一二三四五六七八九"3%Chz64qz"三十八"xJ%Cez64
49 symbols pyth failed test 4 Wrong answer
38
instead of
28
Fri Oct 21 18:33:21 2016 Sait2000
+*T-xJm%Cd64%3tt"十一二三四五六七八九"%Chz64qz"三十八"xJ%Cez64
36 symbols pyth failed test 1 Wrong answer
28
instead of
30
Sat Nov 12 04:03:07 2016 Sait2000
+Ki%2mxiR32"10c9rkd3bt"%Cd32zT*25q3K

View all solutions