用英文写出1到1000的所有数字需要多少个字母?

如果用英文写出数字1到5: one, two, three, four, five, 那么一共需要3 + 3 + 5 + 4 + 4 = 19个字母。

如果数字1到1000(包含1000)用英文写出,那么一共需要多少个字母?

注意: 空格和连字符不算在内。例如,342 (three hundred and forty-two)包含23个字母; 115 (one hundred and fifteen)包含20个字母。"and" 的使用与英国标准一致。

public class Test {
	public static void main(String[] args) {
		String[] m=new String[]{"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};  
		String[] n=new String[]{"","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};  
		  int first,second,three,sum=0;  
		    for (int i=1;i<1000;++i)  
		    {  
		        int a=i%10;//个位数字         
		        int b=(i%100)/10;//十位  
		        int c=i/100;//百位  
		  
		        if(c >= 1)  
		        {  
		            three = m[c].length() + 7;  
		            if(i % 100 != 0)  
		                three += 3;  
		        }  
		        else  
		            three = 0;  
		          
		        if(b >= 2)  
		        {  
		            second = n[b].length();  
		            first = m[a].length();  
		        }  
		        else  
		        {  
		            second = 0;  
		            first = m[i % 100].length();  
		        }  
		        sum = sum + first + second + three;  
		    }  
		    sum+=11;  
		   System.out.println(sum);
		}  
	}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值