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

            vector

            #include <vector>
            #include 
            <string>
            #include 
            <algorithm>
            #include 
            <iterator>
            #include 
            <iostream.h>
            // #include <iostream>

            class GreaterThan {
            public:
                GreaterThan( 
            int size = 6 ) : _size( size ){}
                
            int size() { return _size; }

                
            bool operator()(const string & s1) {
                    
            return s1.size() > 6;
                    }

            private:
                
            int _size;
            };

            template 
            <class Type>
            class PrintElem {
            public:
                
            void operator()( const Type &elem ) 
                {
                    
            ++_cnt;
                    
            if ( _cnt % 8 == 0 ) { cout << endl; }
                    cout 
            << elem << " ";
                }
                
            private:
                
            static int _cnt;
            };

            template 
            < class Type >
                   
            int PrintElem<Type>::_cnt = 0;

            class LessThan {
            public:
                
            bool operator()(const string & s1, const string & s2 ) {
                     
            return s1.size() < s2.size();
                    }
            };

            typedef vector
            <string, allocator> textwords;

            void process_vocab( vector<textwords, allocator> *pvec )
            {
                
            if ( ! pvec ) 
                     
            // issue warning message
                     return;

                vector
            < string, allocator > texts; 

                vector
            <textwords, allocator>::iterator iter = pvec->begin();
                
            for ( ; iter != pvec->end(); ++iter )
                          copy( (
            *iter).begin(), (*iter).end(), back_inserter( texts ));

                
            // sort the elements of texts
                sort( texts.begin(), texts.end() );
                for_each( texts.begin(), texts.end(), PrintElem
            <string>() );

                cout 
            << endl << endl;

                
            // delete all duplicate elements 
                vector<string, allocator>::iterator it;
                it 
            = unique( texts.begin(), texts.end() );
                texts.erase( it, texts.end() );
                for_each( texts.begin(), texts.end(), PrintElem
            <string>() );

                cout 
            << endl << endl;

                stable_sort( texts.begin(), texts.end(), LessThan() );
                for_each( texts.begin(), texts.end(), PrintElem
            <string>() );

                cout 
            << endl << endl;

                
            // count number of strings greater than length 6
                int cnt = 0;

                
            // obsolete form of count -- standard changes this
                count_if( texts.begin(), texts.end(), GreaterThan(), cnt );

                cout 
            << "Number of words greater than length six are "
                         
            << cnt << endl;

                
            // 

                
            static string rw[] = { "and""if""or""but""the" };
                vector
            <string,allocator> remove_words( rw, rw+5 );

                vector
            <string, allocator>::iterator it2 = remove_words.begin();
                
            for ( ; it2 != remove_words.end(); ++it2 ) {
                    
            int cnt = 0;
                    
            // obsolete form of count -- standard changes this
                        count( texts.begin(), texts.end(), *it2, cnt );
                
                    cout 
            << cnt << " instances removed:  " 
                             
            << (*it2) << endl;
                
                        texts.erase(
                            remove(texts.begin(),texts.end(),
            *it2),
                            texts.end()
                       );
                   }

                cout 
            << endl << endl;
                for_each( texts.begin(), texts.end(), PrintElem
            <string>() );
            }

            typedef vector
            <string,allocator>::difference_type diff_type;
            #include 
            <fstream.h>

            main()
            {
                 vector
            <textwords, allocator> sample;
                 vector
            <string,allocator>       t1, t2; 
                 
            string               t1fn, t2fn;

                 cout 
            << "text file #1: "; cin >> t1fn;
                 cout 
            << "text file #2: "; cin >> t2fn;

                 ifstream infile1( t1fn.c_str());
                 ifstream infile2( t2fn.c_str());

                 istream_iterator
            < string, diff_type > input_set1( infile1 ), eos; 
                 istream_iterator
            < string, diff_type > input_set2( infile2 );

                 copy( input_set1, eos, back_inserter( t1 ));
                 copy( input_set2, eos, back_inserter( t2 ));

                 sample.push_back( t1 ); sample.push_back( t2 );
                 process_vocab( 
            &sample );
            }

            posted on 2009-12-21 00:14 蜜蜂 閱讀(207) 評(píng)論(0)  編輯 收藏 引用 所屬分類: VECTOR


            只有注冊用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2009年12月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            亚洲国产精品成人AV无码久久综合影院| 好属妞这里只有精品久久| 久久99精品久久久久久野外| 午夜精品久久久久久影视777 | 中文字幕成人精品久久不卡| 久久精品国产久精国产| 成人精品一区二区久久| 久久久久国产精品嫩草影院| 久久婷婷成人综合色综合| 久久影视综合亚洲| 9久久9久久精品| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久精品国产91久久麻豆自制| 久久久久久噜噜精品免费直播| 色综合久久久久无码专区| 国内精品久久久久久久久| 久久久久AV综合网成人| 亚洲国产婷婷香蕉久久久久久| 91精品国产高清久久久久久io| 久久久久久久免费视频| 久久久久99精品成人片牛牛影视 | 久久久久国产精品麻豆AR影院| 久久人爽人人爽人人片AV| 99精品国产免费久久久久久下载 | 99国产精品久久久久久久成人热| 亚洲人成无码久久电影网站| 91精品国产综合久久四虎久久无码一级| 亚洲AV日韩AV永久无码久久| 欧美与黑人午夜性猛交久久久| 精品久久一区二区三区| 色偷偷久久一区二区三区| 久久久久亚洲av成人网人人软件| 久久成人精品| 亚洲国产香蕉人人爽成AV片久久| 久久精品国产欧美日韩| 久久国产精品无码网站| 精品国产青草久久久久福利| 97精品伊人久久久大香线蕉| 91精品国产91久久久久久| 国产精品久久久久乳精品爆| 日本三级久久网|