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;
    }
    

      

  • 相关阅读:
    Asp.Net服务器控件开发的Grid实现(四)回发事件
    Win8的IIS中架设php
    jsonp其实很简单【ajax跨域请求】
    Asp.Net服务器控件开发的Grid实现(三)列编辑器
    Asp.Net服务器控件开发的Grid实现(二)Html标记渲染
    构建之法阅读笔记01
    四则运算2
    psp0
    随机生成30道四则运算
    学习进度条
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5784742.html
Copyright © 2011-2022 走看看