• <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>

            C小加

            厚德 博學(xué) 求真 至善 The bright moon and breeze
            posts - 145, comments - 195, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
            以前學(xué)數(shù)據(jù)結(jié)構(gòu)的時(shí)候吧字典樹忽視了,導(dǎo)致到現(xiàn)在才學(xué)到。
            字典樹是一種樹形的數(shù)據(jù)結(jié)構(gòu),插入的復(fù)雜度為單詞的平均長度。本題只需要寫一個(gè)插入函數(shù)就可以了。
            由于過幾天就要省賽了,等到省賽后總結(jié)一下字典樹。

            // trietree.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
            //
            #include<cstdio>
            #include<iostream>
            #include<string.h>

            using namespace std;
            const int num_chars = 26;            //關(guān)鍵碼最大位

            int _max;
            char ans[12];

            class Trie
            {
            public:
                Trie();
                Trie(Trie& tr);
                virtual ~Trie();
                //int trie_search(const char* word, char*entry) const;
                bool insert(const char* word);
            protected:
                struct Trie_node   //關(guān)鍵碼類型
                {
                    bool isfin;
                    int cnt;                     //關(guān)鍵碼當(dāng)前位數(shù)
                    Trie_node* branch[num_chars];   //關(guān)鍵碼存放數(shù)組
                    Trie_node();
                };
                Trie_node* root;
            };

            Trie::Trie_node::Trie_node()   //結(jié)點(diǎn)定義
            {
                isfin = false;
                cnt = 0;
                for(int i = 0; i < num_chars;++i)
                    branch[i] = NULL;
            }

            Trie::Trie():root(NULL)
            {
            }

            Trie::~Trie()
            {
            }



            bool Trie::insert(const char*word)
            {
                int result = 1,position = 0;
                if(root == NULL)
                    root = new Trie_node;
                char char_code;
                Trie_node *location = root;
                while(location != NULL && *word != 0)
                {
                    if(*word >= 'a'&& *word <= 'z')
                        char_code = *word - 'a';
                    if(location->branch[char_code] == NULL)
                        location->branch[char_code] = new Trie_node;
                    location = location->branch[char_code];
                    position++;
                    word++;
                }

                ++location->cnt;
                if(location->cnt>_max)
                {
                    _max=location->cnt;
                    return true;
                }
                else
                return false;
            }


            int main()
            {
                Trie t;
                int n;
                while(scanf("%d",&n)!=EOF)
                {
                    _max=0;
                    char s[12];
                    for(int i=0;i<n;++i)
                    {
                        scanf("%s",s);
                        if(t.insert(s))
                        {
                            strcpy(ans,s);
                        }

                    }
                    printf("%s %d\n",ans,_max);
                }


                return 0;
            }
            久久亚洲中文字幕精品有坂深雪 | 色综合久久久久网| 超级碰碰碰碰97久久久久| 激情久久久久久久久久| 久久婷婷国产综合精品| 奇米综合四色77777久久| 久久精品国产亚洲αv忘忧草| 久久青青草原亚洲av无码| 久久精品国产欧美日韩| 久久国产免费观看精品| 久久精品国产99国产电影网| 久久综合综合久久97色| 色噜噜狠狠先锋影音久久| 99精品久久久久久久婷婷| 久久国产午夜精品一区二区三区| 亚洲精品高清国产一久久| 国产女人aaa级久久久级| 日批日出水久久亚洲精品tv| 亚洲精品乱码久久久久久蜜桃| 人人狠狠综合久久亚洲| 久久综合色老色| 麻豆AV一区二区三区久久| 高清免费久久午夜精品| 久久精品国产亚洲5555| 99久久免费国产精品特黄| 亚洲国产精品一区二区久久hs| 精品久久久久香蕉网| 日本福利片国产午夜久久| 久久久WWW成人免费毛片| 久久亚洲精品成人无码网站| 99精品久久久久中文字幕| 精品久久久久久久久久久久久久久| 久久香蕉国产线看观看猫咪?v| 久久人人爽人人爽人人片AV不 | 久久99国产乱子伦精品免费| 99久久无码一区人妻| 久久99这里只有精品国产| 97久久天天综合色天天综合色hd | 精品国产乱码久久久久久人妻| 国产精品毛片久久久久久久| 欧美一级久久久久久久大片|