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

            gzwzm06

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              1 隨筆 :: 52 文章 :: 17 評論 :: 0 Trackbacks
            #include <stdio.h>
            #include 
            <cstring>

            const int MAXN = 131101 ;
            const int SIZE = 100001 ;
            struct HashItem
            {
                
            char matchStr[12] ;
                
            char memStr[12] ;
                HashItem 
            *next ;
                HashItem() 
            {
                    next 
            = NULL ;
                }

            }
            hash[MAXN] , g_Temp[SIZE] ;

            int g_Pos ;

            int RKHash( char *str )
            {
                unsigned 
            long hash = 0 ;

                
            while ( *str )
                
            {
                    hash 
            = (hash * 26+ (*str - 'a') ;
                    str
            ++ ;
                }


                
            return (hash % MAXN) ;
            }


            void Insert( char *str , char *mstr )
            {
                
            int key = RKHash( str ) ;

                HashItem 
            *= &g_Temp[g_Pos++] ;
                strcpy( p
            ->memStr, mstr ) ;
                strcpy( p
            ->matchStr, str ) ;
                p
            ->next = NULL ;
                p
            ->next = hash[key].next ;
                hash[key].next 
            = p ;
                
            }


            int Find( char *str , char *mstr )
            {
                
            int key = RKHash( str ) ;
                
            int pos = 0 ;

                HashItem 
            *= hash[key].next ;

                
            while ( p )
                
            {
                    
            if ( strcmp( p->matchStr, str ) == 0 )
                    
            {
                        pos 
            = 1 ;
                        strcpy( mstr, p
            ->memStr ) ;
                        
            break ;
                    }

                    p 
            = p->next ;
                }

                
                
            return pos ;
            }


            void Init()
            {
                g_Pos 
            = 0 ;

                
            for ( int i = 0 ; i < MAXN ; ++i )
                    hash[i].next 
            = NULL ;
            }


            int main()
            {
                
            char str[2][12] , tmpStr[50] ;
                
            int x ;

                Init() ;

                
            while ( gets(tmpStr) && tmpStr[0] )
                
            {
                    sscanf( tmpStr, 
            "%s%s", str[0], str[1] ) ;

                    Insert( str[
            1], str[0] ) ;
                }


                
            while ( scanf("%s"&str[0]) != EOF )
                
            {
                    x 
            = Find( str[0] , str[1] ) ;

                    
            if ( x == 1 )
                    
            {
                        printf(
            "%s\n", str[1]) ;
                    }

                    
            else {
                        printf(
            "eh\n") ;
                    }

                }


                
            return 0 ;
            }
            posted on 2008-11-09 23:15 閱讀(425) 評論(0)  編輯 收藏 引用 所屬分類: Hash應用
            国产精品久久久久久久人人看| 97精品依人久久久大香线蕉97| 国内精品人妻无码久久久影院| 99久久99这里只有免费的精品| 欧美伊香蕉久久综合类网站| 久久亚洲国产成人影院网站| 久久国产乱子伦免费精品| 精品多毛少妇人妻AV免费久久| 亚洲午夜精品久久久久久浪潮 | 久久e热在这里只有国产中文精品99| 久久国产香蕉视频| 久久发布国产伦子伦精品| 99久久精品无码一区二区毛片 | 热综合一本伊人久久精品| 色综合久久久久综合体桃花网| 久久e热在这里只有国产中文精品99| 婷婷久久五月天| 精品久久久久久无码国产| 国产精品久久久久久福利漫画| 色偷偷91久久综合噜噜噜噜| 久久久国产精品网站| 久久婷婷五月综合色高清| 久久精品国产久精国产果冻传媒 | 国产午夜久久影院| 色偷偷88888欧美精品久久久| 色综合久久88色综合天天 | 99久久国产综合精品网成人影院| 久久精品亚洲中文字幕无码麻豆| 久久久久久精品无码人妻| 伊人色综合久久天天人守人婷| 久久夜色撩人精品国产| 国产免费久久久久久无码| 国产精品日韩深夜福利久久| 91久久精品电影| 精品欧美一区二区三区久久久| 久久久久国产精品| 国产精品成人久久久久三级午夜电影| 久久精品九九亚洲精品| 久久超碰97人人做人人爱| 久久久久久久综合日本亚洲 | 欧美一级久久久久久久大片|