表达数字的英文字母计数
如果把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”的使用方式遵循英式英语的规则。
#include<stdio.h>
int get_letter_nums(int x){
static int arr1[20]={
0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8
};
static int arr2[10]={0,0,6,6,5,5,5,7,6,6};
if(x < 20){
return arr1[x];
}else if (x<100){
return arr2[x / 10] + arr1[x % 10];
}else if(x<1000){
if(x%100==0){
return arr1[x / 100]+7;
}
return arr1[x / 100]+10+get_letter_nums(x % 100);
}else{
return 11;
}
}
int main(){
int ans=0;
for(int i = 1; i <= 1000; i++){
ans+=get_letter_nums(i);
}
printf(\"%d\\n\",ans);
return 0;
}
继续阅读与本文标签相同的文章
上一篇 :
北京移动5G家庭融合套餐来了:169元起
下一篇 :
Android-使用xml文件资源定义菜单
-
阿里云910会员节:开启时光机领会员大礼包,云产品满减优惠活动
2026-05-18栏目: 教程
-
基于宜搭的“报表分析”实践案例
2026-05-18栏目: 教程
-
javascript教程:实现函数柯里化与反柯里化
2026-05-18栏目: 教程
-
基于宜搭的“定时消息通知”实践案例
2026-05-18栏目: 教程
-
AIoT入门:用虚拟设备体验物联网平台设备上云&设备数据存储
2026-05-18栏目: 教程
