• <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 蜜蜂 閱讀(212) 評論(0)  編輯 收藏 引用 所屬分類: VECTOR

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

            導航

            統計

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            日本WV一本一道久久香蕉| 国产精品成人久久久久三级午夜电影| 天天综合久久久网| 久久夜色撩人精品国产| 欧美精品福利视频一区二区三区久久久精品 | 色天使久久综合网天天| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 99久久精品免费国产大片| 热99re久久国超精品首页| 欧美日韩精品久久久久| 蜜臀久久99精品久久久久久小说| 久久99精品国产99久久| 亚洲欧美成人久久综合中文网 | 人人狠狠综合久久亚洲| 久久综合给合久久狠狠狠97色69| 国产农村妇女毛片精品久久| 亚洲国产精品无码久久一区二区| 亚洲国产二区三区久久| 午夜精品久久久久久久| 婷婷久久精品国产| A级毛片无码久久精品免费| 久久久久亚洲av无码专区喷水| 久久精品无码一区二区三区日韩| 久久超乳爆乳中文字幕| 中文精品久久久久人妻不卡| 国产精品伊人久久伊人电影| 久久99精品国产麻豆| 狠狠精品久久久无码中文字幕| 久久男人AV资源网站| 久久亚洲国产午夜精品理论片| 少妇内射兰兰久久| 久久精品国产清自在天天线| 久久久久国产一区二区| 精品久久久久久无码人妻热| 国产一区二区精品久久| 久久99国内精品自在现线| 一本一本久久A久久综合精品 | 久久国产免费直播| 色综合久久最新中文字幕| 久久国产精品国产自线拍免费| 高清免费久久午夜精品|