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. iOS 表视图(UITableVIew)的使用方法(1)表视图的示例

    表视图继承自UIScrollView,所以有着大多UIScrollView的操作特性,诸如手指控制内容的滚动,内容视图到顶端或者低端时的自动反弹等.配合UINavigationController的导 ...

  2. 未能加载文件或程序集“xxxx”或它的某一个依赖项

    一般是解决方案中相互依赖的项目生成的目标平台不一样所致,更改为相同目标即可!

  3. SIM卡厂商的识别方法

    ICCID(SIM卡号码)的定义应该是: 1-6位:国际移动运营商识别码(IMSI),898600为中国移动,898601为中国联通 7-20位:移动和联通的定义是不同的.   中国移动:  第7.8 ...

  4. libCurl的文件上传

    最近在需要使用curl的上传功能,使用libCurl来实现.因此,先使用curl命令操作,然后再使用libCurl实现. 基于Http协议的文件上传的标准方法是: 基于POST Form的文件上传  ...

  5. linux下TUN/TAP虚拟网卡的使用

    转载:http://wushank.blog.51cto.com/3489095/1306849 tun/tap 驱动程序实现了虚拟网卡的功能,tun表示虚拟的是点对点设备,tap表示虚拟的是以太网设 ...

  6. 关于js闭包是否真的会造成内存泄漏(转载)

    闭包是一个非常强大的特性,但人们对其也有诸多无解.一种危言耸听的说法是闭包会造成内存泄露. 局部变量本来应该在函数退出的时候被解除引用,但如果局部变量被封闭在闭包形成的环境中,那么这个局部变量就能一直 ...

  7. C#面向对象编程基础-喜课堂笔记

    **************[5][C#面向对象编程基础]第1讲:类与对象****************                 *************2.1.1_类与对象的概念**** ...

  8. jQuery的fancybox插件

  9. pygame初步(一)绘制一个运动的矩形

    <More Python Programming for the Absolute Beginner>一书中的第二章练习3(P33) 使用Python的Pygame库 import sys ...

  10. Eclipse之报错信息及其解决方案

    一.有很多人都喜欢开发js的时候用aptana,因此在eclipse中集成aptana插件是必须的,可是,在用link方式在eclipse中安装好aptana后,启动时会报如下错误 An intern ...