(Problem 17)Number letter counts
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的更多相关文章
- (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 ... 
- (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 ... 
- (Problem 35)Circular primes
		The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ... 
- (Problem 57)Square root convergents
		It is possible to show that the square root of two can be expressed as an infinite continued fractio ... 
- (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 ... 
- (Problem 13)Large sum
		Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339 ... 
- (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 ... 
- (Problem 70)Totient permutation
		Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ... 
- (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 ... 
随机推荐
- 斯坦福 IOS讲义 课件总结 二
			1,OC里面传参数个数不同,可以是两个完全不同的方法.如 - (void)addCard:(Card *)card atTop:(BOOL)atTop; - (void)addCard:(Card * ... 
- (IOS)关于Xcode的架构(Architectures)设置
			首先来了解一下Architectures中几个参数的含义 ARMv6:ARM11内核用于iPhone2G和iPhone3G中的架构 ARMv7:modern ARM内核用于iPhone3GS和iPho ... 
- Libev学习笔记2
			这一节根据官方文档给出的简单示例,深入代码内部,了解其实现机制.示例代码如下: int main (void) { struct ev_loop *loop = EV_DEFAULT; ev_io_i ... 
- exists
			select count(*) from Table_A where exists (select count(*) from Table_B.Column1 = Table_A.Column1) 该 ... 
- iPhone 真机调试应用程序
			原文:http://blog.sina.com.cn/s/blog_68e753f70100r3w5.html 真机调试iphone应用程序 1.真机调试流程概述 1) 真机调试应用程序, ... 
- C - N皇后问题(搜索)
			Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上. 你的任务是,对于给定的N,求出有多少种合 ... 
- 电信光纤猫 f412超级密码
			中兴F412光猫超级密码破解.破解用户限制.关闭远程控制.恢复路由器拨号 http://bbs.mydigit.cn/simple/?t1021161.html 不少家庭都改了光纤入户,那肯定少不了光 ... 
- UVa---------10935(Throwing cards away I)
			题目: Problem B: Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 ... 
- 网站压力测试之ApacheBench
			ApacheBench是 Apache 附带的一个小工具,专门用于 HTTP Server 的benchmark testing,可以同时模拟多个并发请求.使用yum安装apache,ab工具在/us ... 
- VMWare11虚拟机安装OSX10.9系统资源下载及问题解决
			适配VMware11的MacOSX补丁: http://pan.baidu.com/s/1bnqgtDd 使用方法:将补丁解压到一个完全没有中文的目录下,以管理员方式运行目录中的win-install ... 
