用英文写出1到1000的所有数字需要多少个字母?
2013-03-18 16:46
381 查看
如果用英文写出数字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);
}
}
如果数字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);
}
}
相关文章推荐
- Java进阶之欧拉工程 第十七篇【用英文写出1到1000的所有数字需要多少个字母?】
- 欧拉工程第17题 用英文写出1到1000的所有数字需要多少个字母
- Project Euler17.数字1,2,3使用英文的表示为one,two,three,使用的英文的字母数的总和为3+3+5=11,现有1到1000,使用的英文字母数总和为多少?(空格和连接符不计)
- 《python核心编程第二版》练习题——实现1000以内的所有数字的英文表达
- 字母a-z,数字0-9,现需要其中任意3个作为密码,请输出所有可能组合。
- 2017.3.1word中如何改变所有的英文字母和数字的字体
- 获取包含中文,字母,数字集合的字符串的长度(1个汉字字符存储需要2个字节,1个英文字符存储需要1个字节)
- 最近公司项目需要实现微信的@ 功能,如何判断@前的最后一个字节是什么格式,因为阿拉伯数字和英文字母是不会跳转提醒的
- 现在需要100个随机验证码。每个验证码要求是: 每个验证码是四位 ,验证码可以是数字和字母
- js正则表达式限制文本框只能输入数字,小数点,英文字母,汉字等各类代码
- 1000~ 5000之间有多少整数,其各位数字之和为5,分别是哪些数(例如整数2003的各位数字之和为 2+0+0+3 ,等于5))
- 统计英文字母、空格、数字和其他字符的个数
- 正则表达式限制文本框只能输入数字,小数点,英文字母,汉字
- 第16周-统计出其中英文字母、数字、空格和其他字符的个数
- 输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数
- java实现输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
- 验证中文、英文、电话、手机、邮箱、数字、数字和字母、Url地址和Ip地址的正则表达式
- 挑战能力——数字中不带9的正整数占所有正整数的比例是多少?
- 判断1-1000之间有多少个素数,并输出所有素数
- 作业 4 函数应用输入2个正整数m和n(1≤m,n≤1000),输出m~n之间的所有水仙花数。水仙花数是指各位数字的立方和等于其自身的数。