如果把1到5写成英文单词,分别是:one, two, three, four, five,这些单词一共用了3 + 3 + 5 + 4 + 4 = 19个字母。
如果把1到1000都写成英文单词,一共要用多少个字母?
注意: 不要算上空格和连字符。例如,342(three hundred and forty-two)包含23个字母,而115(one hundred and fifteen)包含20个字母。单词“and”的使用方式遵循英式英语的规则。
package EULER17;
/**
* Created by Administrator on 2016/9/14.
* 如果把1到5写成英文单词,分别是:one, two, three, four, five,这些单词一共用了3 + 3 + 5 + 4 + 4 = 19个字母。
* 如果把1到1000都写成英文单词,一共要用多少个字母?
* 注意: 不要算上空格和连字符。例如,342(three hundred and forty-two)包含23个字母,而115(one hundred and fifteen)包含20个字母。单词“and”的使用方式遵循英式英语的规则。
* 20以下和整十数是全部数字单词,逐个位算长度再稍微加点逻辑判断就成
* 有时设计算法除了时间和空间,还要考虑扩展性
*/
public class EULER17 {
public static void main(String[] args){
int letterNum = 0;
for (int i=1;i<1001;i++){