• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 24,  comments - 0,  trackbacks - 0
            今天刷了3道字典樹
            hdu 1251 1075  1247
            摸板
             1 #include<cstdio>
             2 #include<cstring>
             3 #include<algorithm>
             4 #include<iostream>
             5 using namespace std;
             6 typedef struct node{
             7    int cnt;
             8    struct node *b[26];
             9    void init()
            10    {//printf("bsdfjihsd\n");
            11        memset(b, 0sizeof(b));
            12        cnt = 0;
            13    }
            14 }Tree;
            15 Tree tree[500000];
            16 int cnt = 0;
            17 Tree *root = NULL;
            18 void init()
            19 {
            20     cnt = 0;
            21     root = &tree[cnt++];
            22     root->init();
            23 }
            24 void insert(char* p)
            25 {
            26     node* q = root;
            27     while(*p)
            28     {
            29         int idx = *- 'a';
            30         if(0 == q->b[idx])
            31         {
            32             q->b[idx] = &tree[cnt++];
            33             q->b[idx]->init();
            34         }
            35         q->b[idx]->cnt++;
            36         q = q->b[idx];
            37         p++;
            38     }
            39 }
            40 
            41 int query(char* p)
            42 {
            43     node* q = root;
            44     int ans = 0;
            45     while(*p)
            46     {
            47         int idx = *- 'a';
            48         if(0 == q->b[idx])
            49         {
            50             ans = 0;
            51             return 0;
            52         }
            53         ans = q->b[idx]->cnt;
            54         q = q->b[idx];
            55         p++;
            56     }
            57     return ans;
            58 }
            59 int main()
            60 {
            61     //freopen("in.txt", "r", stdin);
            62     char s[20];
            63     init();
            64     while(gets(s))
            65     {
            66 
            67 
            68         if(strcmp(s,"\0"== 0){break;}
            69         insert(s);
            70     }
            71     while(scanf("%s",s) != EOF)
            72     {
            73         int ans  = query(s);
            74         printf("%d\n",ans);
            75     }
            76     return 0;
            77 }
            78 
            posted on 2011-09-13 20:28 ACSeed 閱讀(138) 評論(0)  編輯 收藏 引用
            久久99国产精品久久| 国产亚洲美女精品久久久2020| 国产精品视频久久| 很黄很污的网站久久mimi色 | 久久精品9988| 久久中文字幕无码专区| 国产激情久久久久久熟女老人| 久久精品人人做人人爽电影| 久久亚洲国产成人影院网站| 久久精品国产亚洲av水果派| 久久精品无码一区二区三区免费 | 99久久精品免费看国产免费| 久久婷婷五月综合成人D啪| 国产精品久久久99| 久久精品麻豆日日躁夜夜躁| 精品国产日韩久久亚洲| 久久精品国产99久久香蕉| WWW婷婷AV久久久影片| 久久妇女高潮几次MBA| 久久精品二区| 日本道色综合久久影院| 99久久久精品免费观看国产| 久久久www免费人成精品| 亚洲va久久久久| 一本久久a久久精品综合香蕉| 久久久久久久久久久免费精品| 久久国产成人精品麻豆| 久久99国产精一区二区三区| 久久无码人妻一区二区三区| 漂亮人妻被中出中文字幕久久| 人妻无码久久精品| 亚洲精品无码久久久| 性做久久久久久久久| 久久久久无码中| 中文字幕无码久久久| 久久婷婷五月综合国产尤物app| 亚洲精品久久久www| 国产精品美女久久福利网站| 国产精品久久久久久久人人看| 国产精品久久久久蜜芽| 77777亚洲午夜久久多喷|