Japanese numeral for Ruby kaigi

Submit

Your name:
File:
Open code-statistics:

Language is selected by the extension of the file. See the list of supported languages to know the extension of your language.

Problem

*** IMPORTANT NOTICE - PLEASE READ ***

This problem is for the golf competition event in Ruby Kaigi (http://jp.rubyist.net/RubyKaigi2008/?Golf). Please don't submit your code until Fri Jun 20 09:00:00 UTC 2008 (1213952400 in unix time) not to scare "ordinary" people by your amazing score :) English problem description follows.

For people who are attending Ruby Kaigi: please use (kaigi) suffix for your name, or you cannot get the award of the competition.

この問題は日本 Ruby 会議 2008 のゴルフコンペティション向けに作られた問題です。本職のゴルファーの方は 18:00 まで投稿を控えていただければありがたいです。本職でなければ Ruby 会議にいらっしゃらない方も投稿していただいて結構です。

Ruby 会議に参加している方は、 (kaigi) というサフィックスを名前につけて投稿するようにして下さい。そうしないと賞品がもらえませんのでご注意を。

=== 問題 ===

入力の各行に、 0 < n < 10000 の範囲の n に関して漢数字表記 (UTF8) にした数値が入ってきます。これを ASCII の表現に変換して、改行を入れつつ出力して下さい。

=== Problem description ===

Each line of the input contains Japanese numeral in UTF8.
Translate the number into ASCII numeral and output them in each line.

Sorry for non-Japanese people, this problem requires brief knowledge
of Japanese numerals. However, I don't think it's too difficult. There
is a way to convert English to Japanese.

1. Suppose you want to convert a number 3141.

2. Create English expression

three thousands one hundred forty one

3. Convert from XXX-ty to "XXX ten".

three thousands one hundred four ten one

4. Remove trailing 's' for multiple thousands and hundreds.

three thousand one hundred four ten one

5. Remove "one" before thousand, hundred, or ten.

three thousand hundred four ten one

6. Translate using the following table:

one: 一
two: 二
three: 三
four: 四
five: 五
six: 六
seven: 七
eight: 八
nine: 九
ten: 十
hundred: 百
thousand: 千

三千百四十一

7. That's all!

As usual, my description isn't so good :( Please check the code which
generated the test case of this challenge

http://golf.shinh.org/mk_kaigi2.txt

and the Wikipedia entry for Japanese numerals

http://en.wikipedia.org/wiki/Japanese_numerals

Options

exec is denied

now post-mortem time, all source codes will be revealed

Sample input:_

千二百三十四
二千三百四十五
九千八百七十六
五千四百三十二
千
百
十
一
百三
三百三
千百十一

Sample output:

1234
2345
9876
5432
1000
100
10
1
103
303
1111

Sample input:_

一
二
三
四
五
六
七
八
九
十
十一
十二
十三
十四
十五
十六
十七
十八
十九
二十
二十一
二十二
二十三
二十四
二十五
二十六
二十七
二十八
二十九
三十
三十一
三十二
三十三
三十四
三十五
三十六
三十七
三十八
三十九
四十
四十一
四十二
四十三
四十四
四十五
四十六
四十七
四十八
四十九
五十
五十一
五十二
五十三
五十四
五十五
五十六
五十七
五十八
五十九
六十
六十一
六十二
六十三
六十四
六十五
六十六
六十七
六十八
六十九
七十
七十一
七十二
七十三
七十四
七十五
七十六
七十七
七十八
七十九
八十
八十一
八十二
八十三
八十四
八十五
八十六
八十七
八十八
八十九
九十
九十一
九十二
九十三
九十四
九十五
九十六
九十七
九十八
九十九
百

Sample output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

Sample input:_

九千百三十三
八千九百六十七
四千六百三十
六百五十一
四千六百五
五千八百九十五
五千二百八十二
六千八百四十四
四千百二十七
六千八百五十六
九千一
六百四十三
六千四十五
九千六百二十二
六千二百八十七
六千二百七
三千五百四十
四千三百二十六
二千三百八十五
千三百八十二
九千三百五
九千五百五十二
四千八十六
四百五十
五千五百十
三千百二十四
千七百八十六
九千八百三十
八千二百十八
七千三百九十三
四千五百七
千五百二十五
九千六百六十二
六千三百八十六
五千四百二十四
百十一
八千五百七十二
百二
九千八百八十九
九千九百四十
二千百六十六
二千六百十一
千百五十二
千九百七十七
六千六百十七
六千百九十三
九千五百六十九
四千六百六十一
七千八百五十五
千八百三十八
八千二百七十
九千六百五十七
七千五百十一
三千五百七十二
八千六十三
四百七十五
九千七百四十七
二千二百四十三
三百二十一
六千五百六
九千三百九十四
五千二百一
八千六百五十五
七千五百六十四
五千二百九十九
千二百七十五
二千七百二十一
四千三百二
八千三百三十九
三千七百四十七
千八百五十一
九百九十二
六千五百九十六
九千二百八十八
三千六百十一
四千七百四十
六千四百三十八
千九十四
三千百六十七
六千百九十六
四千八十
七千五百九十九
六千六百六十九
七千五百三
千三百五十八
八千九百二十七
四千八百八十四
四千五百七十七
八千九百四十二
三千六百十一
千八百六十一
八千六十七
四千四百四
千二百五十
六千四百十七
九千二百七十六
千二百八十
千二百四十七
千九十四
九千二百六十六

Sample output:

9133
8967
4630
651
4605
5895
5282
6844
4127
6856
9001
643
6045
9622
6287
6207
3540
4326
2385
1382
9305
9552
4086
450
5510
3124
1786
9830
8218
7393
4507
1525
9662
6386
5424
111
8572
102
9889
9940
2166
2611
1152
1977
6617
6193
9569
4661
7855
1838
8270
9657
7511
3572
8063
475
9747
2243
321
6506
9394
5201
8655
7564
5299
1275
2721
4302
8339
3747
1851
992
6596
9288
3611
4740
6438
1094
3167
6196
4080
7599
6669
7503
1358
8927
4884
4577
8942
3611
1861
8067
4404
1250
6417
9276
1280
1247
1094
9266

Ranking

Ruby _

RankUserSizeTimeDateStatistics
1shinh1120.30432008/06/20 18:06:0323B / 28B / 55B
2yowa1150.33052008/06/20 18:05:3236B / 21B / 53B
3tal1190.13692008/06/20 18:58:420B / 55B / 61B
4kstn1210.19202008/06/20 18:58:2724B / 46B / 44B
5yvl1250.31392008/06/20 18:37:0336B / 33B / 49B
6tarui1290.14872008/06/20 18:05:0036B / 41B / 48B
7usa (kaigi)1560.20882008/06/20 18:17:0936B / ?B / ?B
8gugod (kaigi)1590.23252008/06/20 18:15:0045B / 38B / 72B
9uru1660.52722008/06/20 18:20:1937B / ?B / ?B
10znz (kaigi)1700.27852008/06/20 18:36:4338B / 42B / 82B
11date (kaigi)1720.19462008/06/20 18:34:3938B / ?B / ?B
12naruse (kaigi)1740.20912008/06/20 18:05:5136B / ?B / ?B
13par1750.23252008/06/20 12:53:4136B / ?B / ?B
14naruse1780.15832008/06/20 16:57:1336B / ?B / ?B
15tommy (kaigi)1860.23592008/06/20 18:41:5173B / ?B / ?B
16HIROX (kaigi)2180.32402008/06/20 18:08:0537B / ?B / ?B
17m-kawato (kaigi)2410.13992008/06/20 18:05:0136B / ?B / ?B
18kenmaz(kaigi)2440.20062008/06/20 17:40:0836B / ?B / ?B
19gugod2480.26422008/06/20 14:44:0845B / ?B / ?B
20taninsw(kaigi)2580.20172008/06/20 18:22:1936B / ?B / ?B
21gunjisatoshi (kaigi)2600.28622008/06/20 18:09:3948B / ?B / ?B
22ksk920.22662008/06/22 00:08:148B / 34B / 44B
23tal1080.23932008/06/21 08:26:160B / 50B / 53B
24yowa1110.37722008/06/20 19:00:4218B / 25B / 63B
25kaki1400.30982008/07/15 02:41:5336B / 54B / 44B
26gugod1520.19082008/06/22 13:47:1945B / 39B / 64B
27gugod (kaigi)1520.32232008/06/22 13:48:2145B / ?B / ?B
28tabasa3060.30882008/06/22 10:41:0876B / ?B / ?B

Perl _

RankUserSizeTimeDateStatistics
1ySas1040.13922008/06/21 10:18:093B / 30B / 65B
2Yappo2000.77402008/06/20 20:54:0336B / ?B / ?B

Python _

RankUserSizeTimeDateStatistics
1yattom(kaigi)2040.45072008/06/20 16:24:2919B / ?B / ?B

Common LISP _

RankUserSizeTimeDateStatistics
1kozima2340.62902008/10/08 10:08:338B / 131B / 76B

JavaScript _

RankUserSizeTimeDateStatistics
1murky-satyr1260.32952008/08/17 22:27:5912B / 59B / 55B
2nn1330.10512008/08/16 20:17:5711B / 65B / 57B
3Tomac2050.01822011/10/03 22:15:010B / ?B / ?B

Smalltalk _

RankUserSizeTimeDateStatistics
1murky-satyr2040.75622008/07/05 00:42:1618B / 85B / 95B

C _

RankUserSizeTimeDateStatistics
151b1560.03622008/06/20 18:32:538B / 73B / 74B
251b1510.03772008/06/21 01:06:538B / 70B / 72B

D _

RankUserSizeTimeDateStatistics
151b1860.05142008/06/24 02:33:108B / 110B / 63B

AWK _

RankUserSizeTimeDateStatistics
1nn1260.08332008/07/16 23:08:3212B / 48B / 66B
2naoya_t2260.01212008/06/22 08:54:0715B / 110B / 99B

Postscript _

RankUserSizeTimeDateStatistics
1yshl(bin)1581.22022008/06/20 19:51:4371B / 53B / 32B
2yshl2821.23042008/06/20 19:51:320B / 204B / 39B

z80 _

RankUserSizeTimeDateStatistics
1kodera780.32162008/06/20 18:47:3749B / 16B / 9B
2kodera730.39762008/06/23 14:53:3740B / 18B / 12B

Groovy _

RankUserSizeTimeDateStatistics
1nn1908.27852009/11/07 23:22:440B / 96B / 92B

Language Ranking_

RankLangUserSizeScore
1z80kodera7310000
2Rubyksk927934
3PerlySas1047019
4AWKnn1265793
5JavaScriptmurky-satyr1265793
6C51b1514834
7Postscriptyshl(bin)1584620
8D51b1863924
9Groovynn1903842
10Pythonyattom(kaigi)2043578
11Smalltalkmurky-satyr2043578
12Common LISPkozima2343119

return to the top page