• <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年11月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            常用鏈接

            留言簿(24)

            隨筆分類(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

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

             

            這幾天一直很YM..... 糾結(jié).....  做個水題 1075......WA N次.....YM.
            (  很簡單的一題,  檢索輸入的串是否存在, 存在就替換輸出, 不存在直接輸出就可以了 )
            最后無奈, 純C++ STL..過了, 時間竟然用了 1600+MS 還是 C++交的,  G++要3400+MS,  不
            明白為什么時間差那么多,  用trie 做了次, 250MS...   改了好幾次效率都上不來   ....  YM 中 把trie 寫成了 偽 map ,只有一點簡單的功能,
            其他的不想寫了.  寫得好復(fù)雜.................... 
            偽 map 代碼如下 :  好長.....................
            /*
            MiYu原創(chuàng), 轉(zhuǎn)帖請注明 : 轉(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)帖請注明 : 轉(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;

            }


             

             

             

             

            欧美亚洲国产精品久久高清| 91性高湖久久久久| 久久偷看各类wc女厕嘘嘘| 影音先锋女人AV鲁色资源网久久| 久久精品国产亚洲AV忘忧草18| 伊人久久大香线蕉亚洲| 国产精品久久久久久久久| 99久久精品国产综合一区| 久久人人爽人人爽人人片AV麻烦| 国产成人精品综合久久久久| 国产高清国内精品福利99久久| 欧美午夜A∨大片久久| 99久久婷婷国产综合亚洲| 精品国产日韩久久亚洲| 久久99热这里只有精品国产| 久久久久久九九99精品| 伊人色综合九久久天天蜜桃| 国产 亚洲 欧美 另类 久久 | 色诱久久久久综合网ywww| 青青热久久国产久精品| 国产AV影片久久久久久| 国产精品久久久久jk制服| 久久久久波多野结衣高潮| 亚洲国产成人久久综合野外| 九九热久久免费视频| 国产精品伊人久久伊人电影| 国产精品天天影视久久综合网| 亚洲另类欧美综合久久图片区| 亚洲第一永久AV网站久久精品男人的天堂AV| 麻豆成人久久精品二区三区免费 | 国产精品久久久久9999| 久久精品国产91久久麻豆自制| 久久精品国内一区二区三区| 久久99精品久久久久久久不卡 | 久久久久亚洲av毛片大| 伊人久久一区二区三区无码| 久久国产免费观看精品3| 99久久免费国产精品| 久久精品国产亚洲AV蜜臀色欲 | 久久无码中文字幕东京热| 国产精品久久久久久久|