Water problem
来源:互联网 发布:cisco端口看环路 编辑:程序博客网 时间:2024/05/23 23:18
Water problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
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 n (up to one thousand) inclusive were written out in words, how many letters would be used?
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.
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.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases.
For each test case: There is one positive integer not greater one thousand.
For each test case: There is one positive integer not greater one thousand.
Output
For each case, print the number of letters would be used.
Sample Input
3123
Sample Output
3611
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;int main(){int i,t,j,cot,n,m;int a[100]={4,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8,6};//0-20int b[100]={4,3,6,6,5,5,5,7,6,6};//0,10,20,..90scanf("%d",&t);while(t--){scanf("%d",&m);cot=0;for(i=1;i<=m;i++){n=i;if(n<=20){cot+=a[n];}else if(n>20&&n<1000){int sum=0,mark=0;if(n>=100){sum+=a[n/100]+7;n=n%100;mark=1;}if(n>20){if(mark==1)sum+=3;if(n%10==0){sum+=b[n/10];}else{sum+=b[n/10]+a[n%10];}}else if(n>0){if(mark==1)sum+=3;sum+=a[n];}cot+=sum;}else if(n==1000)cot+=11;}printf("%d\n",cot);}return 0;}
0 0
- Water problem
- A simple water problem
- 1810: water problem II
- A water problem
- Water and Jug Problem
- A water problem
- hdu5832 A water problem
- A water problem
- A water problem
- A water problem
- hdu 5867 Water problem
- 【HDU5867】Water problem(模拟)
- HDU 5867 Water problem
- HDU 5867 Water problem
- Water and Jug Problem
- hdoj5867 Water problem
- HDU 5867 Water problem
- A water problem
- 文件的上传
- Android Studio 生成所有文件的JavaDoc文档
- 如何使用maven建一个web3.0的项目
- mkdir
- Java中获取Log4j日志文件,Mybatis 的ScriptRunner执行带pl/sql的 代码块脚本
- Water problem
- Java的位运算符详解实例——与(&)、非(~)、或(|)、异或(^)
- servlet属性值的改变;
- scp在本地和远程端传送文件
- 测试web页面下的过滤器
- 《关于大数据的一些基本常识整理》
- GridView/ListView与ScrollView冲突解决办法
- linux源码编译的过程
- LINUX 单个用户访问权限控制(ACL)