(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 ...
随机推荐
- TMOUT
设置TMOUT可以踢用户,直接从shell端. 实际上如果ssh或telnet也可以在其配置里面设定.
- 射频识别技术漫谈(14)——Mifare S50与S70的存取控制
存取控制指符合什么条件才能对卡片进行操作. S50和S70的块分为数据块和控制块,对数据块的操作有“读”.“写”.“加值”.“减值(含传输和存储)”四种,对控制块的操作只有“读”和“写”两种. S50 ...
- Session()
如何使用 Session Java Api 只给我们一种方式来 获取 当前会话相关的 session: HttpSession session = request.getSession(); //或 ...
- 17.1.2.1 Advantages and Disadvantages of Statement-Based and Row-Based Replication
17.1.2.1 Advantages and Disadvantages of Statement-Based and Row-Based Replication 基于语句和基于行复制的优点和缺点: ...
- 01_什么是Elasticsearch
Logstash是一个开源的用于收集,分析和存储日志的工具. Kibana4用来搜索和查看Logstash已索引的日志的web接口.这两个工具都基于 Elasticsearch. Logstash: ...
- HDU 1870 愚人节的礼物
题解:简单的数括号问题…… #include <cstdio> char s[1005]; int main(){ while(scanf("%s",s)!=EOF){ ...
- 提高你的Java代码质量吧:使用valueof前必须进行校验
一.分析 每个枚举都是java.lang.Enum的子类,都可以访问Enum类提供的方法,比如hashCode.name.valueOf等,其中valueOf方法会把一个String类型的名称转变成枚 ...
- (转)跟我一起写MAKEFILE
概述 —— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的程序员,makef ...
- 文字适应DIV
今天突然碰到了一个奇怪的问题 那就是对于纯数字和英文字母 文字多了会超出div 且即使是设置了height:auto overflow-y:auto 也不管用 只是在x轴上出现滚动条 不论用 ...
- js求指定时间的周一和周日
/*计算指定时间的的周一和周日 return=>{mondy:Date,sundy:Date} parms:{ date:指定时间,如果不指定则取当前时间 } */ function getWe ...