zoukankan      html  css  js  c++  java
  • codevs 1729 单词查找树

    二次联通门 : codevs 1729 单词查找树

    /*
        codevs 1729 单词查找树
         
         
        Trie树
        
        统计节点个数
        建一棵Trie树
        插入单词时每新开一个节点就计数器加1
         
    */
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    
    void read (int &now)
    {
        now = 0;
        register char word = getchar ();
        while (word < '0' || word > '9')
            word = getchar ();
        while (word >= '0' && word <= '9')
        {
            now = now * 10 + word - '0';
            word = getchar ();
        }
    }
    
    struct Trie_Type
    {
    
        struct Trie
        {
            Trie *next[26];
            bool Add_flag;
            bool flag;
        };
            
        Trie Root;
        
        int Count;
         
        void Insert (char *line)
        {
            int Length = strlen (line);
            Trie *now = &Root;
            Trie *res;
            for (int i = 0; i < Length; i++)
            {
                int name = line[i] - 'A';
                if (now->next[name] == NULL)
                {
                    res = (Trie *) malloc (sizeof Root);
                    res->flag = true;
                    for (int j = 0; j < 26; j++)
                        res->next[j] = NULL;
                    now->next[name] = res;
                    Count++;
                    now = now->next[name];
                }
                else
                {
                    now->next[name]->flag = true;
                    now = now->next[name];
                }
            }
        }
        
        void Clear ()
        {
            for (int i = 0; i < 26; i++)
                Root.next[i] = NULL;
        }
        
    };
    
    Trie_Type Make;
    int N;
    
    int main (int argc, char *argv[])
    {
        Make.Clear ();
        register char word[65];
        while (scanf ("%s", word) != EOF)
            Make.Insert (word); 
        printf ("%d", Make.Count + 1);
        return 0;
    }
  • 相关阅读:
    如何快速转载CSDN及博客园中的博客
    Ubuntu18.04连不网 报"有线连接未托管"
    Ubuntu18.04的网络配置
    vim基本操作
    Git更新远程仓库代码到本地(转)
    POJ 3253 Fence Repair
    POJ 2503 Babelfish
    POJ 2002 Squares
    POJ 1840 Eqs
    POJ 3274 Gold Balanced Lineup
  • 原文地址:https://www.cnblogs.com/ZlycerQan/p/6753759.html
Copyright © 2011-2022 走看看