HDU 5867Water problem 题如其名

来源:互联网 发布:淘宝自动刷销量软件 编辑:程序博客网 时间:2024/06/01 09:08
Water problem
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 5867

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

3123

Sample Output

3611

#include <iostream>#include <stdio.h>using namespace std;int main(){    int a[1000+5] = {0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8,6};    a[30]=6;    a[40]=5;    a[50]=5;    a[60]=5;    a[70]=7;    a[80]=6;    a[90]=6;    a[100]=10;    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]=11;    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