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

            C++研究

            C++細節(jié)深度探索及軟件工程

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              37 隨筆 :: 0 文章 :: 74 評論 :: 0 Trackbacks
            #include "stdafx.h"
            #include 
            <iostream>
            #include 
            <map>
            #include 
            <sstream>
            using namespace std;

            #pragma warning (disable:
            4305)

            typedef map
            <intfloat> FloatMap;
            typedef FloatMap::iterator FloatMapIter;
            typedef FloatMap::const_iterator FloatMapCIter;
            int main()
            {
                FloatMap _map1, _map2;
                _map1[
            1= 0.01;
                _map1[
            3= 0.03;
                _map1[
            4= 0.04;
                _map1[
            5= 0.05;
                _map1[
            7= 0.07;
                _map1[
            101= 0.101;
                _map1[
            109= 0.109;

                _map2[
            1= 0.01;
                _map2[
            4= 0.04;
                _map2[
            5= 0.05;
                _map2[
            7= 0.07;
                _map2[
            101= 0.101;
                _map2[
            103= 0.103;
                _map2[
            108= 0.108;

                FloatMapCIter it1 
            = _map1.begin();
                FloatMapCIter it2 
            = _map2.begin();

                FloatMapCIter it22 
            = _map2.begin();
                FloatMapCIter it11 
            = _map1.begin();
                ostringstream os1; 
            //fenzi
                ostringstream os11; //fenmu1
                ostringstream os22; //fenmu2

                
            //是否有公共部分
                int flag = 0;

                
            while(it1 != _map1.end())
                
            {
                    
            int id = (*it1).first;
                    
            float v1 = (*it1).second;

                    
            while( it22 != _map2.end() && (*it22).first < id) ++it22;

                    
            if( it22 == _map2.end())
                    
            {
                        
            break;
                    }


                    
            if( (*it22).first == id )
                    
            {
                        
            //有公共部分
                        flag = 1;
                        os1 
            << (*it22).first <<  "  "//fenzi
                        cout << (*it22).second << "*" << v1 << endl;
                        it22
            ++;
                    }

                    
            //it2 -- it22
                    FloatMapCIter itemp = it2;
                    
            while( itemp != it22)
                    
            {
                        os22 
            << (*itemp).first << "  " ; //fenmu
                        ++itemp;
                    }

                    it2 
            = it22;
                    
                    
            int id2 = (*it2).first;
                    
            float v2 = (*it2).second;
                    
            while( it11 != _map1.end() && (*it11).first < id2)
                    
            {
                        
            ++it11;
                    }


                    
            if ( it11 == _map1.end())
                    
            {
                        
            break;
                    }


                    
            if( (*it11).first == id2 )
                    
            {
                        
            //有公共部分
                        flag = 1;
                        os1 
            << (*it11).first << "  "//fenzi
                        cout << (*it11).second << "*" <<  v2 << "  ";
                        it11
            ++;
                    }

                    itemp 
            = it1;
                    
            while( itemp != it11)
                    
            {
                        os11 
            << (*itemp).first << "  " ; //fenmu
                        ++itemp;
                    }
                
                    it1 
            = it11;    

                }
            //while

                
            //是否有公共部分
                if (flag == 1)
                
            {
                    
            while( it2 != _map2.end() )
                    
            {
                        os22 
            << (*it2).first << "  " ; //fenmu
                        ++it2;
                    }


                    
            while( it1 != _map1.end() )
                    
            {
                        os11 
            << (*it1).first << "  " ; //fenmu
                        ++it1;
                    }

                }

                
            else
                
            {
                    
            return 0;
                }

                
                    
                


                cout 
            << "Common:" << os1.str() << endl;
                cout 
            << "fenmu:" << os11.str() << endl;
                cout 
            << "fenmu:" << os22.str() << endl;

                system(
            "pause");

                
            return 0;
            }
            posted on 2008-01-15 21:12 常興龍 閱讀(2185) 評論(1)  編輯 收藏 引用 所屬分類: STLAlgorithmACM

            評論

            # re: 求有序序列公共部分(集合交集的O(n)復(fù)雜度求法) 2014-04-10 15:34 黃智
            取交集可不是這么取的吧?一趟循環(huán)即可!  回復(fù)  更多評論
              

            > hi的博客
            蜜臀av性久久久久蜜臀aⅴ| 亚洲AV无码一区东京热久久| 人妻无码精品久久亚瑟影视 | 国内精品久久久久影院日本| 欧美性猛交xxxx免费看久久久| 国产激情久久久久影院小草 | 久久WWW免费人成—看片| 69SEX久久精品国产麻豆| 国内精品久久久久影院日本| 2021久久国自产拍精品| 国产精品18久久久久久vr | 久久91精品国产91久久户| 久久精品国产半推半就| 99久久久精品免费观看国产| 狠狠色丁香久久婷婷综合五月| 国产精品久久久天天影视| 青草影院天堂男人久久| 国产午夜电影久久| 深夜久久AAAAA级毛片免费看| 久久久精品久久久久影院| 7777久久久国产精品消防器材 | 国产高潮国产高潮久久久91| 久久精品国产99久久香蕉| 亚洲精品久久久www| 7777精品久久久大香线蕉| 99久久婷婷国产综合精品草原| 久久国产香蕉一区精品| 久久人人爽人人爽人人片AV高清| 91精品国产乱码久久久久久| 国产精品久久久久久久午夜片 | 久久午夜无码鲁丝片秋霞| 久久亚洲精品国产精品| 国产精品亚洲美女久久久| 亚洲精品午夜国产VA久久成人| 久久婷婷综合中文字幕| 无码人妻少妇久久中文字幕 | 婷婷久久香蕉五月综合加勒比| 色综合久久中文综合网| 久久人妻少妇嫩草AV蜜桃| 国产精品无码久久四虎| 亚洲精品无码久久千人斩|