• <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>
            struct TreeNode //結點
            {
                
            char EN_word[25];
                TreeNode 
            *next[26];
                TreeNode()
            //構造函數做初始化
                {
                    EN_word[
            0]='\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 *EN_word,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();
                        
            if(i==len-1)//判斷是否最后一個字符,附加信息放在這里
                            strcpy(loca->next[ban]->EN_word,EN_word);
                    }
                    i
            ++;
                    loca
            =loca->next[ban];
                }
            }
            bool search(TreeNode *&root,const char * MA_word)
            {
                TreeNode 
            * loca=root;
                
            int i=0,ban=0;
                
            char ans[25];
                
            int len=strlen(MA_word);
                
            if(MA_word[0== ' 'return 0;
                
            if(MA_word[0== '\n'return 0;
                
            while(MA_word[i])
                {
                    ban
            =MA_word[i]-'a';
                    
            if(!loca->next[ban])
                        
            return 0;
                    loca 
            = loca->next[ban];
                    i 
            ++;
                }

                strcpy(ans,loca
            ->EN_word);
                
            if(ans[0== '\0'return 0;
                printf(
            "%s",ans);
                
            return 1;
            }
            int main()
            {
                freopen(
            "in.txt","r",stdin);
                
            int n,i;
                
            char c;
                
            char str1[25],str2[25];
                
            struct TreeNode *headNode = NULL;
                
            while(true)
                {
                    scanf(
            "%s",str1);
                    
            if(strcmp(str1,"END")==0)  break;
                    
            if(strcmp(str1,"START")==0continue;
                    scanf(
            "%s",str2);
                    insert(headNode,str1,str2);

                }
                getchar();
                gets(str2);
                i 
            = 0;
                
            while(true)
                {
                    c 
            = getchar();
                    
            if(c =='E'break;
                    
            /*while((c=getchar() ) && islower(c))
                        str1[++i] = c;
            */
                    
            while(1)// 只是這里在處理字符串的時候 樣例過了 但是提交報內存錯誤
                    {
                        str1[i
            ++= c;
                        c 
            = getchar();
                        
            if(!islower(c))
                        {
                            str1[i] 
            = '\0';
                            
            break;
                        }
                    }
                    
            if(search(headNode,str1)==0) printf("%s",str1);
                    
            if(c != 'E')printf("%c",c);
                    
            if(c =='E'break;
                    i 
            = 0;
                    
                }
                
            return 0;
            }

            下面的是正確的
            #include<stdio.h>
            #include
            <string.h>
            #include
            <ctype.h>
            struct TreeNode //結點
            {
                
            char EN_word[25];
                TreeNode 
            *next[26];
                TreeNode()
            //構造函數做初始化
                {
                    EN_word[
            0]='\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 *EN_word,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();
                        
            if(i==len-1)//判斷是否最后一個字符,附加信息放在這里
                            strcpy(loca->next[ban]->EN_word,EN_word);
                    }
                    i
            ++;
                    loca
            =loca->next[ban];
                }
            }
            bool search(TreeNode *&root,const char * MA_word)
            {
                TreeNode 
            * loca=root;
                
            int i=0,ban=0;
                
            char ans[25];
                
            int len=strlen(MA_word);
                
            if(MA_word[0== ' 'return 0;
                
            if(MA_word[0== '\n'return 0;
                
            while(MA_word[i])
                {
                    ban
            =MA_word[i]-'a';
                    
            if(!loca->next[ban])
                        
            return 0;
                    loca 
            = loca->next[ban];
                    i 
            ++;
                }

                strcpy(ans,loca
            ->EN_word);
                
            if(ans[0== '\0'return 0;
                printf(
            "%s",ans);
                
            return 1;
            }
            int main()
            {
                freopen(
            "in.txt","r",stdin);
                
            int n,i;
                
            char c;
                
            char str1[25],str2[25];
                
            struct TreeNode *headNode = NULL;
                
            while(true)
                {
                    scanf(
            "%s",str1);
                    
            if(strcmp(str1,"END")==0)  break;
                    
            if(strcmp(str1,"START")==0continue;
                    scanf(
            "%s",str2);
                    insert(headNode,str1,str2);

                }
                getchar();
                gets(str2);
                i 
            = 0;
                
            while(true)
                {
                    c 
            = getchar();
                    
            if(c =='E'break;
                    
            /*while((c=getchar() ) && islower(c))
                        str1[++i] = c;
            */
                    str1[i
            ++= c;
                    
            if(c < 'a' || c > 'z')
                    {
                        str1[i
            -1= '\0';
                        
            if(search(headNode,str1)==0) printf("%s",str1);
                        
            if(c != 'E')printf("%c",c);
                        
                         i 
            = 0;
                    }
                    
                    
            //i++;
                    
                }
                
            return 0;
            }

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

            <2010年7月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            常用鏈接

            留言簿(2)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            CSDN - 我的blog地址

            博客

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久婷婷国产麻豆91天堂| 超级97碰碰碰碰久久久久最新 | …久久精品99久久香蕉国产 | 中文字幕无码久久人妻| 久久毛片一区二区| 久久精品国产亚洲AV高清热| 久久精品国产亚洲AV不卡| 中文精品99久久国产| 久久精品天天中文字幕人妻| 国产福利电影一区二区三区久久久久成人精品综合 | 奇米影视7777久久精品人人爽| 国产91久久精品一区二区| 久久99精品九九九久久婷婷| 久久人做人爽一区二区三区| 精品久久久久久久无码| 7777精品伊人久久久大香线蕉| 狠狠色丁香久久婷婷综| 亚洲中文字幕无码久久综合网 | 久久久久亚洲精品无码网址| 日本人妻丰满熟妇久久久久久| 国内精品免费久久影院| 国产精品岛国久久久久| 久久亚洲私人国产精品| 国内精品伊人久久久久妇| 久久不见久久见免费影院www日本| 亚洲国产精品成人久久| 亚洲欧美国产精品专区久久 | 国内精品久久久久伊人av| 2020久久精品亚洲热综合一本| 精品久久久久久无码人妻热| 国产精品久久久久无码av| 亚洲成色www久久网站夜月| 少妇无套内谢久久久久| 久久久精品国产| 亚洲一区精品伊人久久伊人| 色综合久久夜色精品国产| 国产香蕉久久精品综合网| 久久亚洲sm情趣捆绑调教| 久久人人爽人人爽人人片av麻烦 | 大香网伊人久久综合网2020| 久久中文字幕一区二区|