(Problem 17)Number letter counts

时间:2022-09-13 11:37:49

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.

题目大意:

如果用英文写出数字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" 的使用与英国标准一致。

// (Problem 16)Number letter counts
// Completed on Sun, 17 Nov 2013, 16:30
// Language: C
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/#include <stdio.h>
#include <stdbool.h> int a[] = {,,,,,,,,,,,,,,,,,,,}; void init(void) //初始化数组
{
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
a[] = ;
} int within100(void) //计算1~99所含字母的和
{
int i, sum, t;
t = sum = ;
for(i = ; i <= ; i++) t += a[i];
for(i = ; i <= ; i++) sum += a[i];
for(i = ; i <= ; i++) {
sum += a[i*] * ;
sum += t;
}
return sum;
} void solve(void)
{
int i;
int sum, t;
sum = t = within100();
for(i = ; i < ; i++) {
sum += (a[i] + ) * + (a[i] + ) + t;
}
sum += ; printf("%d\n",sum);
} int main(void)
{
init();
solve();
return ;
}
Answer:
21124

(Problem 17)Number letter counts的更多相关文章

  1. (Problem 28)Number spiral diagonals

    Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...

  2. (Problem 42)Coded triangle numbers

    The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...

  3. (Problem 35)Circular primes

    The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...

  4. (Problem 57)Square root convergents

    It is possible to show that the square root of two can be expressed as an infinite continued fractio ...

  5. (Problem 16)Power digit sum

    215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of th ...

  6. (Problem 13)Large sum

    Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339 ...

  7. (Problem 41)Pandigital prime

    We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...

  8. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  9. (Problem 74)Digit factorial chains

    The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...

随机推荐

  1. python2&period;x 默认编码问题

    python2.x中处理中文,是一件头疼的事情.网上写这方面的文章,测次不齐,而且都会有点错误,所以在这里打算自己总结一篇文章. 我也会在以后学习中,不断的修改此篇博客. 这里假设读者已有与编码相关的 ...

  2. &lbrack;转&rsqb;嵌入式SQC文件编译

      Src Url:http://blog.csdn.net/cws1214/article/details/12996351   A.预编译部分  1.预编译DB2篇 1.1 什么是DB2预编译 在 ...

  3. ssh curl 命令理解

    使用一条命令抓取一本小说 curl "http://www.23hh.com/book/1/1019/"|iconv -c -f gbk -t utf8 |sed 's/&quot ...

  4. 023使用typeof关键字获取类内部结构

    private void button1_Click(object sender, EventArgs e) { Focus(); string a=txtType.Text; // Type typ ...

  5. Wim技术之Wim文件的制作

    背景:操作的镜像文件为win8.1 update的ISO里的Wim文件 1.使用如下命令将支持WimBoot的instal.Wim文件转换成可以支持wimboot启动的映像文件 Dism /Expor ...

  6. SpringNote02&period;Blog系统迁移到Linux下

    基于SpringMVC-Hibernate的博客系统还在继续开发中 . 项目地址:https://github.com/defshine/SpringBlog 整个项目迁移到linux下开发,安装in ...

  7. dplyr 数据操作 常用函数(5)

    继续来了解dplyr中的其他有用函数 1.sample() 目的是可以从一个数据框中,随机抽取一些行,然后组成新的数据框. sample_n(tbl, size, replace = FALSE, w ...

  8. Utils 工具 推送

    work_weipa_百度云推送 2014-09-05 17:55 7人阅读 评论(0) 收藏 举报 问题:怎么实现消息推送? 回答:下载sdk,根据文档操作即可 资料:http://develope ...

  9. awk批量处理文件夹中所有文件

       #c=``     done

  10. 接口自动化测试:python&plus;json&plus;requests&plus;数据驱动

    接口测试是单元测试的一个子集,但又不等同于单元测试.从测试的角度来看,接口测试的价值在于其测试投入比单元测试少,而且技术难度也比单元测试小.一般来说,接口测试的粒度要比单元测试更粗,它主要是基于子系统 ...