#2016多校训练Contest10: 1011 Water problem hdu5867

题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5867

Water problem

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

题意

题意很简单么就是让你求出1-n这n个数字的英文长度,比如输入是2,就是让你求1-2的这段所有数字的英文长度和,1是one,长度是3,2是two,长度是3,所以总共长度是6,还有注意不含’-‘。

方法

可以先把几个特殊的求出来,比如1-20啥的,然后是整10的比如30,40,50…然后就可以很容易的推出1-100,100-1000则只要加前缀的几百就行了。

代码

这题是队友打的,就贴队友的了。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdlib>
#include<iomanip>
#include<string>
#include<vector>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
#define Max(a,b) (a>b)?a:b
#define lowbit(x) x&(-x)

int main()
{
    int a[1005]={0};
    a[1]=3;
    a[2]=3;
    a[3]=5;
    a[4]=4;
    a[5]=4;
    a[6]=3;
    a[7]=5;
    a[8]=5;
    a[9]=4;
    a[10]=3;
    a[11]=6;
    a[12]=6;
    a[13]=8;
    a[14]=8;
    a[15]=7;
    a[16]=7;
    a[17]=9;
    a[18]=8;
    a[19]=8;
    a[20]=6;
    a[30]=6;
    a[40]=5;
    a[50]=5;
    a[60]=5;
    a[70]=7;
    a[80]=6;
    a[90]=6;
    a[100]=3+7;

    for(int i=20;i<100;i+=10)
    {
        for(int j=i+1;j<i+10;j++)
            a[j]=a[i]+a[j-i];
    }
    for(int i=100;i<1000;i+=100)
    {
        a[i]=a[i/100]+7;
        for(int j=i+1;j<=i+99;j++)
        {
            a[j]=a[i]+3+a[j-i];
        }
    }
    a[1000]=3+8;
    for(int i=2;i<=1000;i++)
        a[i]+=a[i-1];
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        printf("%d\n",a[n]);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值