Water problem HDU - 5867

问一个数字 转换成英文后,一共有多少个字母比如 342 (three hundred and forty-two)有 23 个字母代码里直接打了个表,就是data[]那个表,其实也可以去掉这个表,data_是0 ~ 20对应的英文单词的字母个数,data_2是 20~90 整数的英文单词的字母个数,通过Cal()就可以计算

//leehaoze
#include <iostream>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;
const int INF = 1 << 29;
#define INC_SAT(val) (val = ((val)+1 > (val)) ? (val)+1 : (val))
#define ARR_SIZE(a) ( sizeof( (a) ) / sizeof( (a[0]) ) )
#define ULL unsigned long long


int data_[] = {4, 3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8, 6}; // 0 ~ 20

int data_2[] = {0, 0, 6, 6, 5, 5, 5, 7, 6, 6}; // 20 ~ 90

int data[] = {3,6,11,15,19,22,27,32,36,39,45,51,59,67,74,81,90,98,106,112,121,130,141,151,161,170,181,192,202,208,217,226,237,247,257,266,277,288,298,303,311,319,329,338,347,355,365,375,384,389,397,405,415,424,433,441,451,461,470,475,483,491,501,510,519,527,537,547,556,563,573,583,595,606,617,627,639,651,662,668,677,686,697,707,717,726,737,748,758,764,773,782,793,803,813,822,833,844,854,864,880,896,914,931,948,964,982,1000,1017,1033,1052,1071,1092,1113,1133,1153,1175,1196,1217,1236,1258,1280,1304,1327,1350,1372,1396,1420,1443,1462,1484,1506,1530,1553,1576,1598,1622,1646,1669,1687,1708,1729,1752,1774,1796,1817,1840,1863,1885,1903,1924,1945,1968,1990,2012,2033,2056,2079,2101,2119,2140,2161,2184,2206,2228,2249,2272,2295,2317,2337,2360,2383,2408,2432,2456,2479,2504,2529,2553,2572,2594,2616,2640,2663,2686,2708,2732,2756,2779,2798,2820,2842,2866,2889,2912,2934,2958,2982,3005,3015,3031,3047,3065,3082,3099,3115,3133,3151,3168,3184,3203,3222,3243,3264,3284,3304,3326,3347,3368,3387,3409,3431,3455,3478,3501,3523,3547,3571,3594,3613,3635,3657,3681,3704,3727,3749,3773,3797,3820,3838,3859,3880,3903,3925,3947,3968,3991,4014,4036,4054,4075,4096,4119,4141,4163,4184,4207,4230,4252,4270,4291,4312,4335,4357,4379,4400,4423,4446,4468,4488,4511,4534,4559,4583,4607,4630,4655,4680,4704,4723,4745,4767,4791,4814,4837,4859,4883,4907,4930,4949,4971,4993,5017,5040,5063,5085,5109,5133,5156,5168,5186,5204,5224,5243,5262,5280,5300,5320,5339,5357,5378,5399,5422,5445,5467,5489,5513,5536,5559,5580,5604,5628,5654,5679,5704,5728,5754,5780,5805,5826,5850,5874,5900,5925,5950,5974,6000,6026,6051,6071,6094,6117,6142,6166,6190,6213,6238,6263,6287,6307,6330,6353,6378,6402,6426,6449,6474,6499,6523,6543,6566,6589,6614,6638,6662,6685,6710,6735,6759,6781,6806,6831,6858,6884,6910,6935,6962,6989,7015,7036,7060,7084,7110,7135,7160,7184,7210,7236,7261,7282,7306,7330,7356,7381,7406,7430,7456,7482,7507,7518,7535,7552,7571,7589,7607,7624,7643,7662,7680,7697,7717,7737,7759,7781,7802,7823,7846,7868,7890,7910,7933,7956,7981,8005,8029,8052,8077,8102,8126,8146,8169,8192,8217,8241,8265,8288,8313,8338,8362,8381,8403,8425,8449,8472,8495,8517,8541,8565,8588,8607,8629,8651,8675,8698,8721,8743,8767,8791,8814,8833,8855,8877,8901,8924,8947,8969,8993,9017,9040,9061,9085,9109,9135,9160,9185,9209,9235,9261,9286,9306,9329,9352,9377,9401,9425,9448,9473,9498,9522,9542,9565,9588,9613,9637,9661,9684,9709,9734,9758,9769,9786,9803,9822,9840,9858,9875,9894,9913,9931,9948,9968,9988,10010,10032,10053,10074,10097,10119,10141,10161,10184,10207,10232,10256,10280,10303,10328,10353,10377,10397,10420,10443,10468,10492,10516,10539,10564,10589,10613,10632,10654,10676,10700,10723,10746,10768,10792,10816,10839,10858,10880,10902,10926,10949,10972,10994,11018,11042,11065,11084,11106,11128,11152,11175,11198,11220,11244,11268,11291,11312,11336,11360,11386,11411,11436,11460,11486,11512,11537,11557,11580,11603,11628,11652,11676,11699,11724,11749,11773,11793,11816,11839,11864,11888,11912,11935,11960,11985,12009,12019,12035,12051,12069,12086,12103,12119,12137,12155,12172,12188,12207,12226,12247,12268,12288,12308,12330,12351,12372,12391,12413,12435,12459,12482,12505,12527,12551,12575,12598,12617,12639,12661,12685,12708,12731,12753,12777,12801,12824,12842,12863,12884,12907,12929,12951,12972,12995,13018,13040,13058,13079,13100,13123,13145,13167,13188,13211,13234,13256,13274,13295,13316,13339,13361,13383,13404,13427,13450,13472,13492,13515,13538,13563,13587,13611,13634,13659,13684,13708,13727,13749,13771,13795,13818,13841,13863,13887,13911,13934,13953,13975,13997,14021,14044,14067,14089,14113,14137,14160,14172,14190,14208,14228,14247,14266,14284,14304,14324,14343,14361,14382,14403,14426,14449,14471,14493,14517,14540,14563,14584,14608,14632,14658,14683,14708,14732,14758,14784,14809,14830,14854,14878,14904,14929,14954,14978,15004,15030,15055,15075,15098,15121,15146,15170,15194,15217,15242,15267,15291,15311,15334,15357,15382,15406,15430,15453,15478,15503,15527,15547,15570,15593,15618,15642,15666,15689,15714,15739,15763,15785,15810,15835,15862,15888,15914,15939,15966,15993,16019,16040,16064,16088,16114,16139,16164,16188,16214,16240,16265,16286,16310,16334,16360,16385,16410,16434,16460,16486,16511,16523,16541,16559,16579,16598,16617,16635,16655,16675,16694,16712,16733,16754,16777,16800,16822,16844,16868,16891,16914,16935,16959,16983,17009,17034,17059,17083,17109,17135,17160,17181,17205,17229,17255,17280,17305,17329,17355,17381,17406,17426,17449,17472,17497,17521,17545,17568,17593,17618,17642,17662,17685,17708,17733,17757,17781,17804,17829,17854,17878,17898,17921,17944,17969,17993,18017,18040,18065,18090,18114,18136,18161,18186,18213,18239,18265,18290,18317,18344,18370,18391,18415,18439,18465,18490,18515,18539,18565,18591,18616,18637,18661,18685,18711,18736,18761,18785,18811,18837,18862,18873,18890,18907,18926,18944,18962,18979,18998,19017,19035,19052,19072,19092,19114,19136,19157,19178,19201,19223,19245,19265,19288,19311,19336,19360,19384,19407,19432,19457,19481,19501,19524,19547,19572,19596,19620,19643,19668,19693,19717,19736,19758,19780,19804,19827,19850,19872,19896,19920,19943,19962,19984,20006,20030,20053,20076,20098,20122,20146,20169,20188,20210,20232,20256,20279,20302,20324,20348,20372,20395,20416,20440,20464,20490,20515,20540,20564,20590,20616,20641,20661,20684,20707,20732,20756,20780,20803,20828,20853,20877,20897,20920,20943,20968,20992,21016,21039,21064,21089,21113,21124};

int Cal(int num) {
    if (num >= 0 && num <= 20) {
        return data_[num];
    } else if (num > 20 && num < 100) {
        if (num % 10 == 0) {
            return data_2[num / 10];
        } else {
            return data_[num % 10] + data_2[num / 10];
        }
    } else if (num >= 100 && num <= 999) {
        if (num % 100 == 0) {
            return data_[num / 100] + 7;
        }
//        else if(num / 10 % 10 == 0){
//            return data_[num / 100] + 7 + 3 + data_[num % 10];
//        }
//        else if(num % 10 == 0){
//            return data_[num / 100] + 7 + 3 + data_2[num / 10 % 10];
//        }
//        else{
//            return data_[num / 100] + 7 + 3 + data_2[num / 10 % 10] + data_[num % 10];
//        }
        else {
            int nn = num % 100;
            int sum = 0;
            if (nn >= 0 && nn <= 20) {
                sum += data_[nn];
            } else if (nn > 20 && nn < 100) {
                if (nn % 10 == 0) {
                    sum += data_2[nn / 10];
                } else {
                    sum += data_[nn % 10] + data_2[nn / 10];
                }
            }
            sum += data_[num / 100] + 7 + 3;
            return sum;
        }
    } else if (num == 1000) {
        return data_[num / 1000] + 8;
    }
}

int main() {
#ifdef LOCAL
    freopen("IN.txt", "r", stdin);
#endif
    int T;
    while (scanf("%d", &T) != EOF) {
        while (T--) {
            int num;
            scanf("%d", &num);
            printf("%d\n",data[num-1]);
        }
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值