zoukankan      html  css  js  c++  java
  • hdu-5867 Water problem(水题)

    题目链接:

    Water problem

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 23    Accepted Submission(s): 14


    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]这些数字用英文单词表示的时候一共用了多少个字母;
     
    思路:
     
    水题;
     
    AC代码:
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
    #include <map>
     
    using namespace std;
     
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
     
    typedef  long long LL;
     
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
     
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=1e9;
    const int N=5e5+10;
    const int maxn=(1<<20)+14;
    const double eps=1e-12;
    
    int dp[1100];
    
    int check(int x)
    {
        if(x<=10)
        {
            if(x==1||x==2||x==6||x==10)return 3;
            else if(x==3||x==7||x==8)return 5;
            else if(x==4||x==5||x==9)return 4;
        }
        else if(x<=20)
        {
        if(x==11||x==12||x==20)return 6;
        if(x==13||x==14||x==18||x==19)return 8;
        if(x==15||x==16)return 7;
        if(x==17)return 9;
        }
        else if(x<100)
        {
            if(x%10==0)
            {
                if(x==30||x==80||x==90)return 6;
                else if(x==40||x==50||x==60)return 5;
                else if(x==70)return 7;
            }
            else return check(x%10)+check(x-x%10);
        }
        else if(x<1000)
        {
            if(x%100==0)return check(x/100)+7;
            else return check(x/100)+10+check(x-(x/100)*100);
        }
        else return 11;
    }
    inline void Init()
    {
        for(int i=1;i<=1000;i++)
        {
            dp[i]=dp[i-1]+check(i);
        }
    }
    
    int main()
    {
        int t;
        Init();
        read(t);
        while(t--)
        {
            int n;
            read(n);
            print(dp[n]);
        }
        return 0;
    }
    

      

  • 相关阅读:
    【推荐】微服务分布式企业框架Springmvc+mybatis+shiro+Dubbo+ZooKeeper+Redis
    将WCF寄宿在托管的Windows服务中
    剑指Offer
    剑指Offer
    Entity Framework 无法对没有主键的视图映射实体的解决办法
    设置Sql Agent运行Job时的执行账户
    IE中Keep-Alive机制引起的错误
    Ajax错误 “SCRIPT7002: XMLHttpRequest: 网络错误 0x2ef3, 由于出现错误 00002ef3 而导致此项操作无法完成” 的归纳总结
    在IIS站点中Adomd.net集成认证账号问题
    出现“不能执行已释放的Script代码”错误的原因及解决办法
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5784742.html
Copyright © 2011-2022 走看看