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

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2010年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(24)

            隨筆分類(lèi)(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋    

             

            這幾天一直很YM..... 糾結(jié).....  做個(gè)水題 1075......WA N次.....YM.
            (  很簡(jiǎn)單的一題,  檢索輸入的串是否存在, 存在就替換輸出, 不存在直接輸出就可以了 )
            最后無(wú)奈, 純C++ STL..過(guò)了, 時(shí)間竟然用了 1600+MS 還是 C++交的,  G++要3400+MS,  不
            明白為什么時(shí)間差那么多,  用trie 做了次, 250MS...   改了好幾次效率都上不來(lái)   ....  YM 中 把trie 寫(xiě)成了 偽 map ,只有一點(diǎn)簡(jiǎn)單的功能,
            其他的不想寫(xiě)了.  寫(xiě)得好復(fù)雜.................... 
            偽 map 代碼如下 :  好長(zhǎng).....................
            /*
            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋
                      http://www.cnblog.com/MiYu
            Author By : MiYu
            Test      : 4
            Program   : 1075
            */

            #include <iostream>
            #include <string>
            using namespace std;
            typedef struct dict DIC;
            DIC *root = NULL;
            string ext = "";
            struct dict {
                   dict (){ str = "";memset ( child , 0 , sizeof ( child ) ); }
                   ~dict () { }
                   void del ( DIC * node );
                   string & insert ( char *ins,char *key = NULL );
                   string & find ( char *ins );
                   string & operator [] ( char *a );
                   string & operator = ( char *a );
                   DIC *child[26];
                   string str; 
            };
            void dict::del ( DIC * node )
            {
                 if ( node == NULL ) return;
                 for ( int i = 0; i != 26; ++ i )
                 {
                      if ( node->child[i] != NULL )  del ( node->child[i] );
                 }
                 node->str = "";
                 free ( node );  
            }
            string & dict::operator [] ( char *a )
            {
                   string &str = find ( a );
                   if ( str == "" )
                       return  insert ( a );  
                   return str;
            }
            string & dict::operator = ( char *a )
            {
                  return this->str = a; 
            }
            string & dict::insert ( char *ins,char *key )
            {
                        DIC *cur = this,*now;
                        int len = strlen ( ins );
                        for ( int i = 0; i != len; ++ i )
                        {
                              if ( cur->child[ ins[i] - 'a' ] != NULL ) 
                              {
                                   cur = cur->child[ ins[i] - 'a' ];
                              }
                              else
                              {
                                   now = new DIC;
                                   cur->child[ ins[i] - 'a' ] = now;
                                   cur = now;
                              }
                        } 
                        return cur->str;
            }
            string & dict::find ( char *ins )
            {
                        DIC *cur = this;
                        int len = strlen ( ins );
                        for ( int i = 0; i != len; ++ i )
                        {
                             if ( cur->child[ ins[i] - 'a' ] != NULL )
                                  cur = cur->child[ ins[i] - 'a' ];  
                             else
                                  return ext; 
                        } 
                        return cur->str;
            }
            char words[3010],temp[12],t[12];
            int main ()
            {
                DIC dict;
                root = &dict;
                scanf ( "%s", t );
                while ( scanf ( "%s", t ), strcmp ( t, "END" ) != 0 )
                {
                       scanf ( "%s", temp );
                       dict[temp] = t;
                }
                scanf ( "%s", t );
                getchar();
                while ( gets ( words ) && strcmp ( words, "END" ) != 0 )
                {
                       memset ( temp, 0, sizeof ( temp ) );
                       int len = strlen ( words );
                       for ( int i = 0,j = 0; i != len; ++ i )
                       {
                            if ( isalpha ( words[i] ) )
                            {
                                 temp[j++] = words[i];
                            } 
                            else 
                            {
                                 temp[j] = '\0';
                                 string str = dict[ temp ];
                                 if ( str == "" )
                                      printf ( "%s",temp ); 
                                 else
                                      printf ( "%s",str.c_str() );
                                 putchar ( words[i] );
                                 j = 0; 
                            }
                       }
                       putchar ( 10 );
                }
                return 0;
            }

             

             STL 代碼如下 :  好短....

             /*

            MiYu原創(chuàng), 轉(zhuǎn)帖請(qǐng)注明 : 轉(zhuǎn)載自 ______________白白の屋

                      http://www.cnblog.com/MiYu

            Author By : MiYu

            Test      : 1

            Program   : 1075

            */


            #include <iostream>

            #include <string>

            #include <map>

            using namespace std;

            string words,temp;

            map < string , string > mp;

            int main ()

            {

                cin >> words;

                while ( cin >> words, words != "END" )

                {

                       cin >> temp;

                       mp[ temp ] = words;

                }

                cin >> words;

                getchar();

                while ( getline ( cin, words ) && words != "END" )

                {

                       string out = "";

                       int len = words.size();

                       for ( int i = 0; i != len; ++ i )

                       {

                            if ( isalpha ( words[i] ) )

                            {

                                 out += words[i];

                            } 

                            else 

                            {

                                 if ( mp[out] == "" )

                                      cout << out; 

                                 else

                                      cout << mp[out];

                                 cout << words[i];

                                 out = ""; 

                            }

                       }

                       cout << endl;

                }

                return 0;

            }


             

             

             

             

            亚洲精品综合久久| 久久精品国产亚洲AV高清热| 狠狠色婷婷综合天天久久丁香| 久久www免费人成看片| 国产毛片欧美毛片久久久 | 国产精品久久久久9999高清| 欧美大香线蕉线伊人久久| 日韩精品久久无码人妻中文字幕 | 久久一区二区三区99| 亚洲精品无码专区久久同性男| 久久精品免费一区二区| 久久精品亚洲日本波多野结衣 | 奇米影视7777久久精品| 一本色道久久88加勒比—综合| 久久久99精品成人片中文字幕| 久久人人添人人爽添人人片牛牛| 精品永久久福利一区二区| 99久久精品九九亚洲精品| 亚洲婷婷国产精品电影人久久| 久久综合亚洲欧美成人| 久久久久女人精品毛片| 久久婷婷五月综合色奶水99啪| 久久国产亚洲精品无码| 77777亚洲午夜久久多人| 777久久精品一区二区三区无码| 欧美激情精品久久久久久久九九九 | 久久r热这里有精品视频| 狠狠色综合网站久久久久久久| 青青青青久久精品国产 | jizzjizz国产精品久久| 久久久九九有精品国产| 久久毛片一区二区| 成人资源影音先锋久久资源网| 久久er热视频在这里精品| 日韩欧美亚洲综合久久影院Ds| 久久婷婷五月综合国产尤物app | 久久综合色之久久综合| 久久五月精品中文字幕| 一本久久a久久精品综合香蕉 | 免费一级欧美大片久久网| 久久99精品久久久久久噜噜|