Problem 17 Number letter counts (统计字母)
来源:互联网 发布:阿里云飞天六部 编辑:程序博客网 时间:2024/06/05 11:30
Number letter counts
Problem 17
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算到100,再从100 算到1000.
代码:
#include <bits/stdc++.h>using namespace std;int main(){ //1-9 int s1[] = { 0, 3, 3, 5, 4, 4, 3, 5, 5, 4 }; //10-19 int s2[] = { 3, 6, 6, 8, 8, 7, 7, 9, 8, 8 }; //20 30 40 50 60 70 80 90 int s3[] = { 0, 0, 6, 6, 5, 5, 5, 7, 6, 6 }; int hundred = 7; int And = 3; int thousand = 8; int i; int sum = 0; //1-9 for (i = 1; i < 10; i++) { sum += s1[i]; } //10-19 for (i = 0; i < 10; i++){ sum += s2[i]; } //20-99 for (i = 20; i < 100; i++){ sum += s3[i/10] + s1[i%10]; } //100-999 for (i = 1; i < 10; i++) { int j; //计算hundred sum += s1[i] + hundred; // i*100 + j for (j = 1; j < 10; j++){ sum += s1[i] + hundred + And + s1[j]; } //i*100 + j*10 for (j = 0; j < 10; j++) { sum += s1[i] + hundred + And + s2[j]; } //i*100 +j*10 +k for (j = 20; j < 100; j++) { sum += s1[i] + hundred + And + s3[j/10] + s1[j%10]; } } //1000 sum += 3 + thousand; cout<<sum<<endl; return 0;}
1 0
- Problem 17 Number letter counts (统计字母)
- Problem 17:Number letter counts
- Project Euler: Problem 17 Number letter counts
- Project Euler Problem 17 Number letter counts
- PE 17 Number letter counts
- project euler 17 Number letter counts
- 欧拉项目 第17题 Number letter counts
- LeetCode 17 Letter Combinations of a Phone Number(电话号码的字母组合)
- 17:Letter Combinations of a Phone Number(字母组合的电话号码)
- LeetCode 17 Letter Combinations of a Phone Number 数字转为字母组合
- Leetcode #17 Letter Combinations of a Phone Number Z9键盘字母组合解题小节
- leetcode——Letter Combinations of a Phone Number 手机按键字母组合(AC)
- LeetCode 17. Letter Combinations of a Phone Number(键盘字母)
- 425.Letter Combinations of a Phone Number-电话号码的字母组合(中等题)
- 17. Letter Combinations of a Phone Number(根据手机按键求字母的组合)
- Letter Combinations of a Phone Number (电话号码字母组合) 【leetcode】
- LeetCode17——Letter Combinations of a Phone Number(手机几个按键对应的字母(符号)组合)
- LeetCode (17)Letter Combinations of a Phone Number
- 《您的设计模式》(CBF4LIFE)之“责任链模式”【整理】
- 传感器的原理
- 基于Buildroot的linux下交叉编译器的安装
- 批量执行dos2unix,unix2dos
- 移动设备的界面设计尺寸
- Problem 17 Number letter counts (统计字母)
- 常见的管理学中的原理
- mysql 的函数用法SUBSTRING_INDEX
- LeetCode-206. Reverse Linked List
- C++中的内联函数inline总结
- 回退版本
- Leetcode 126. Word Ladder II[hard]
- oracle使用DBMS_SCHEDULER调度作业
- Python列表乘法小记