• <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 - 106,  comments - 32,  trackbacks - 0
            #include<stdio.h>
            #include
            <string.h>
            #include
            <ctype.h>
            const int maxN = 12;
            char word[4= "hat";

            struct TreeNode //結點
            {
                
            //char EN_word[maxN];
                TreeNode *next[26];
                
            int count;
                TreeNode()
            //構造函數做初始化
                {
                    
            //EN_word[0]='\0';
                    count = 0;
                    
            for(int i=0;i<26;i++) next[i]=NULL;
                }
                
            ~TreeNode()//析構函數做善后工作
                {
                    
            for(int i=0;i<26;i++)
                        
            if(next[i]!=NULL) delete next[i];
                }
            };
            void insert(TreeNode *&root,const char * MA_word)//插入結點
            {
                TreeNode 
            * loca=root;
                
            int i=0,ban=0;
                
            if(loca==NULL){loca = new TreeNode();root=loca;}
                
            int len=strlen(MA_word);
                
            while(MA_word[i])
                {
                    ban
            =MA_word[i]-'a';
                    
            if(!loca->next[ban])
                    {
                        loca
            ->next[ban]=new TreeNode();
                    }
                    loca
            ->count ++;
                    i
            ++;
                    loca
            =loca->next[ban];
                }
                loca
            ->count ++;
            }

            void count(TreeNode *&root,int &data)
            {
                TreeNode 
            * loca=root;
                
            int i;
                data 
            += loca->count;
                
            for(i = 0 ; i <26; i ++)
                    
            if(loca->next[i])
                        count(loca
            ->next[i],data);

            }
            int search(TreeNode *&root,const char *keyWord)
            {
                TreeNode 
            * loca=root;
                
            int ban=0,j,len = strlen(keyWord),data = 0,flag;
                
            char ans[maxN];
                
            for(flag = 0,j = 0 ; j < len ; j ++)//測定前面的len深度 是否有keyword
                {
                    ban 
            = keyWord[j]-'a';
                    
            if(loca->next[ban])
                     loca 
            = loca->next[ban];
                    
            else 
                    {
                        flag 
            = 1;
                        
            break;
                    }/*

                    else loca = NULL 以前這里是這樣做的 很清楚 這為后來出現內存錯誤 埋下隱患 
            */
                }
                
            if(flag==0)
                {
                    
                     
            return loca->count;
                }
                
            return 0;
                
            }
            int main()
            {
                
            //freopen("in.txt","r",stdin);
                int n,i;
                
            char c;
                
            char str1[maxN],str2[maxN];
                
            struct TreeNode *headNode = NULL;
                
            while(1)
                {
                    gets(str1);
                    
            if(strcmp(str1,"")==0)
                        
            break;
                    insert(headNode,str1);
                }
                
            while(scanf("%s",str1)!=EOF)
                {
                    printf(
            "%d\n",search(headNode,str1));
                }
                
            return 0;
            }

            posted on 2010-07-19 14:57 付翔 閱讀(221) 評論(0)  編輯 收藏 引用 所屬分類: ACM 數據結構

            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            CSDN - 我的blog地址

            博客

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲欧美成人综合久久久| 久久国产精品-国产精品| 久久午夜无码鲁丝片午夜精品| 久久久久无码精品国产app| 中文字幕无码久久人妻| 国产精品美女久久久久久2018 | 怡红院日本一道日本久久 | 色偷偷88欧美精品久久久| 久久久久这里只有精品| 色欲综合久久躁天天躁蜜桃| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 99re这里只有精品热久久| 久久伊人五月天论坛| 99久久99这里只有免费费精品| 久久99国产精品成人欧美| 日产精品久久久久久久| 久久久WWW免费人成精品| 999久久久无码国产精品| 亚洲精品99久久久久中文字幕| 久久久精品午夜免费不卡| 色欲久久久天天天综合网| 久久久久亚洲AV无码专区网站| 97超级碰碰碰久久久久| 亚洲成色WWW久久网站| 狠狠色丁香久久婷婷综合图片| 久久国产午夜精品一区二区三区| 亚洲欧美日韩中文久久| 久久天天躁夜夜躁狠狠躁2022| 久久久久久久综合综合狠狠| 精品午夜久久福利大片| 久久精品国产亚洲77777| 亚洲人成伊人成综合网久久久| 欧美日韩精品久久久久| 亚洲精品高清一二区久久| 亚洲综合久久夜AV | 合区精品久久久中文字幕一区| 久久99精品久久久久久齐齐 | 久久久久久无码国产精品中文字幕 | 久久久噜噜噜久久中文字幕色伊伊 | 久久男人AV资源网站| 午夜精品久久久久久久无码|