Python实现欧拉计划17题

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?


NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.

--------------------------------------------------------------------------------------------------------------------------------------

d={1:3,2:3,3:5,4:4,5:4,6:3,7:5,8:5,9:4,10:3,20:6,30:6,40:5,50:5,60:5,70:7,80:6,90:6,11:6,12:6,13:8,14:8,15:7,16:7,17:9,18:8,19:8}
L=[]
for i in range(1,1000):
    m=0
    if 20>=i>=1:
        m=d[i]
    elif 99>=i>=21:
        if i%10==0:
            m=d[i]
        else :
            a=int(i/10)
            b=int(i%10)
            m=d[a*10]+d[b]
            d[i]=m   
    else :
        c=i%100
        e=int(i/100)
        if c==0:           
            m=7+d[e]
        else :
            m=10+d[e]+d[c]
    L.append(m)
a=sum(L)+11
print a
print L
print len(L)

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值