hdu 5867 Water【水题】
2016-08-18 20:31
429 查看
Water problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 84 Accepted Submission(s): 64
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.
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.
Output
For each case, print the number of letters would be used.
Sample Input
3
1
2
3
Sample Output
3
6
11
Author
BUPT
Source
2016 Multi-University Training Contest 10
题目大意:
给你一个正整数n,让你求从1到n的所有数字的英文表达式的字母个数和。
思路:
①处理一下1-20的每个数字对应英文的个数处理到一个数组中
②处理一下30-90中%10==0的数字对应英文的个数到一个数组中
③对应将百和and两个单词处理到一个定义变量中
④然后分类讨论即可,具体参考代码;
AC代码:
#include<string.h>
#include<stdio.h>
using namespace std;
int gewei[1000]={0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8,6};//1-20
int shiwei[1000]={0,0,6,6,5,5,5,7,6,6};
#define bai 7
#define andd 3
int cal(int x)
{
if(x==1000)return 11;
if(x%100==0)
{
return bai+gewei[x/100];
}
if(x<=20)return gewei[x];
if(x>20&&x<100)
{
return shiwei[x/10]+gewei[x%10];
}
if(x>100)
{
int tmpp=gewei[x/100]+bai+andd;
x%=100;
if(x<=20)tmpp+=gewei[x];
if(x>20&&x<=100)tmpp+=shiwei[x/10]+gewei[x%10];
return tmpp;
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
int output=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
output+=cal(i);
}
printf("%d\n",output);
}
}
相关文章推荐
- HDU 5832 A water problem 水题
- hdu-5867 Water problem(水题)
- HDU 5443 The Water Problem(水题 找区间最大值)——2015 ACM/ICPC Asia Regional Changchun Online
- hdu 5867 Water problem(2016 Multi-University Training Contest 10——水题)
- HDU 5443 The Water Problem(线段树水题)
- hdu 4974 A simple water problem(水题)
- HDU 5443 The Water Problem【RMQ水题】
- 【2016-CCPC-A】水题(A water problem,hdu 5832)
- hdu 4974 A simple water problem(多校第十场 水题)
- HDU 5867 Water problem(复杂水题)
- Water problem HDU - 5867
- HDU 5832 A water problem (带坑水题)
- hdu 5443 The Water Problem(长春网络赛 水题)
- HDU 5832 A water problem (水题)
- Water problem HDU - 5867
- 水题(Water problem,HDU 5867)
- Water problem HDU - 5867
- HDU 5867 Water problem (模拟水题)
- Water problem HDU - 5867
- hdu1412 set函数的第一次成功应用 超级水题