67 lines
1.0 KiB
Python
67 lines
1.0 KiB
Python
dic = {
|
|
0:'',
|
|
1:'one',
|
|
2:'two',
|
|
3:'three',
|
|
4:'four',
|
|
5:'five',
|
|
6:'six',
|
|
7:'seven',
|
|
8:'eight',
|
|
9:'nine',
|
|
10:'ten',
|
|
11:'eleven',
|
|
12:'twelve',
|
|
13:'thirteen',
|
|
14:'fourteen',
|
|
15:'fifteen',
|
|
16:'sixteen',
|
|
17:'seventeen',
|
|
18:'eighteen',
|
|
19:'nineteen',
|
|
20:'twenty',
|
|
30:'thirty',
|
|
40:'forty',
|
|
50:'fifty',
|
|
60:'sixty',
|
|
70:'seventy',
|
|
80:'eighty',
|
|
90:'nithty',
|
|
100:'hundred',
|
|
1000:'thousand'
|
|
}
|
|
|
|
def analyse(x, p = 0):
|
|
if p: print x,
|
|
if x == 1000:
|
|
if p: print dic.get(x)
|
|
return len(dic.get(x))
|
|
out = 0
|
|
tmp = x / 100
|
|
if tmp:
|
|
out += len(dic.get(tmp))
|
|
if p: print dic.get(tmp),
|
|
out += len(dic.get(100))
|
|
if p: print dic.get(100),
|
|
if x % 100 == 0:
|
|
if p: print
|
|
return out
|
|
out += 3
|
|
if p: print 'and',
|
|
tmp = x % 100
|
|
if tmp < 20:
|
|
out += len(dic.get(tmp))
|
|
if p: print dic.get(tmp)
|
|
return out
|
|
out += len(dic.get(tmp / 10 * 10))
|
|
if p: print dic.get(tmp / 10 * 10),
|
|
out += len(dic.get(tmp % 10))
|
|
if p: print dic.get(tmp % 10)
|
|
return out
|
|
|
|
|
|
total = 0
|
|
for i in xrange(1, 1001):
|
|
total += analyse(i)
|
|
print total
|