dポイントプレゼントキャンペーン実施中!

C言語で、入力された数値を英単語に変換するプログラムを作りますが、0~999,999,999 までの整数値について,正しく英単語に変換できるところとします。プログラミングが本当に苦手で、いったいどこから始めばいいのか、さっぱりわかりません。どうか教えてください。
できれば、詳しく説明して頂ければ、助かります。

A 回答 (5件)

ほい。



面倒だからPythonでやったけど、感じはつかめるでしょ。
はっきりいってやっつけだから、このロジックで組んでも
課題とかなら点数はもらえないと思うよ。

微妙に要求を外してるしね :)

#!/usr/bin/python
# coding: utf-8
lessthan21 = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
____________ "ten", "eleven", "twelove", "thirteen", "fourteen", "fifteen",
____________ "sixteen", "seventeen", "eighteen", "nineteen", "twenty"]

tens = ["twenty", "thity", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"]

def to_string(num):
____if num >= 1000*1000*1000:
________print "Give up!!(%d)" % num
________return

____if num <= 20:
________if num != 0:
____________print lessthan21[num],
____elif num < 100:
________print tens[(num / 10)-2],
________to_string(num % 10)
____elif num < 1000:
________to_string(num / 100)
________print "handred",
________to_string(num % 100)
____elif num < 1000000:
________to_string(num / 1000)
________print "thousand",
________to_string(num % 1000)
____elif num <= 1000000000:
________to_string(num / 1000000)
________print "million",
________to_string(num % 1000000)


for n in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,32,
________ 43,54,65,76,87,98,100,101,111, 123, 255,
________ 999, 2001, 9999, 10000, 999999, 1000000, 1001011,
________ 1000*1000*1000-1, 1000*1000*1000]:
____print n, "->",
____to_string(n)
____print

1 -> one
2 -> two
3 -> three
4 -> four
5 -> five
6 -> six
7 -> seven
8 -> eight
9 -> nine
10 -> ten
11 -> eleven
12 -> twelove
13 -> thirteen
14 -> fourteen
15 -> fifteen
16 -> sixteen
17 -> seventeen
18 -> eighteen
19 -> nineteen
20 -> twenty
21 -> twenty one
32 -> thity two
43 -> fourty three
54 -> fifty four
65 -> sixty five
76 -> seventy six
87 -> eighty seven
98 -> ninety eight
100 -> one handred
101 -> one handred one
111 -> one handred eleven
123 -> one handred twenty three
255 -> two handred fifty five
999 -> nine handred ninety nine
2001 -> two thousand one
9999 -> nine thousand nine handred ninety nine
10000 -> ten thousand
999999 -> nine handred ninety nine thousand nine handred ninety nine
1000000 -> one million
1001011 -> one million one thousand eleven
999999999 -> nine handred ninety nine million nine handred ninety nine thousand nine handred ninety nine
1000000000 -> Give up!!(1000000000)
    • good
    • 0

#2 で書いたことをもう一度繰り返すんだけど,


あなたは「100」という数値を見たときに, どのように考えて「one hundred」という英語にしてますか?
あなたは「432143213」という数値を見たときに, どのように考えて「four hundred thirty-two million one hundred forty-three thousand two hundred thirteen」という英語にしてますか?
「アルゴリズムもわからない」ということはありえないはずです.
    • good
    • 0

>1,000,000,000の英単語


数を表す単語なら0-9までと桁上がり10,100,1000,100万,1兆
くらいあればいけるのでは?
あとは組み合わせですし。
Zeor,One,Two,Three,Four,Five,
Six,Seven,Eight,Nine,
ten,hundred,thousand,million,trillion

>詳しく説明して頂ければ
何について詳しく説明してほしいのでしょうか?

この回答への補足

num: 100
English: one hundred
num: 432143213
English: four hundred thirty-two million one hundred forty-three thousand two hundred thirteen.

こういう風な結果がでるようにしたいですが。
プログラミングが全然かけないんです。
アルゴリズムまたはプログラミング自体を説明してほしいです。
素人と同じなので、なんとかお願いします。

補足日時:2007/12/20 10:47
    • good
    • 0

「自分だったらどのようにやるか」を書いてみてください.


プログラミングはそれから.
    • good
    • 0

変換という表現がどういう意図なのかがわからないですが、1,000,000,000個の英単語がそれぞれの数値に対応するということでしょうか??


↑これも意味が通じにくいですね orz 例を示してもらえるとわかりやすいです。

まず、1,000,000,000の英単語をリスト化したファイルを用意して、C言語のプログラムでは単にそのファイルを参照して読み出し というスタイルをとるのが最も簡単化と思います。データ数が莫大なので多少の工夫が必要かと思いますが。

この回答への補足

1,000,000,000の英単語をリスト化したファイルを用意するってどういうことですか。
一つ一つ全部違うから、どうやればいいですか。

補足日時:2007/12/20 22:22
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!