zoukankan      html  css  js  c++  java
  • multimap-constructors

    ////////////////////////////////////////
    //      2018/05/02 15:31:13
    //      multimap-constructors
    #include <iostream>
    #include <map>
    
    using namespace std;
    
    int main(){
        /*
    
        *   multimap特性以及用法与map完全相同,唯一的差别在于:
        *   允许重复键值的元素插入容器(使用了RB-Tree的insert_equal函数)
    
        */
        typedef multimap<int, char, less<int>> M;
        M m1;
    
        m1.insert(M::value_type(2,'B'));
        m1.insert(M::value_type(3,'C'));
        m1.insert(M::value_type(1,'A'));
        m1.insert(M::value_type(1,'a'));
    
        M::iterator it = m1.begin();
        cout << "m1:" << endl;
        while (it != m1.end()){
            cout << it->first << "-" << it->second << endl;
            it++;
        }
    
        // copy constructor
        M m2(m1);
    
        it = m2.begin();
        cout << "m2:" << endl;
        while (it != m2.end()){
            cout << it->first << "-" << it->second << endl;
            it++;
        }
    
        cout << "m3:" << endl;
        M m3(m2.begin(), m2.end());
        it = m3.begin();
        while (it != m3.end()){
            cout << it->first << "-" << it->second << endl;
            it++;
        }
        return 0;
    }
    
    /*
    OUTPUT:
        m1:
        1-A
        1-a
        2-B
        3-C
        m2:
        1-A
        1-a
        2-B
        3-C
        m3:
        1-A
        1-a
        2-B
        3-C
    */ 
  • 相关阅读:
    bzoj3293 分金币
    考前模板整理
    CF785D Anton and School
    容斥法解决错排问题
    CF1248F Catowice City
    CF1248E Queue in the Train
    CF1244F Chips
    CF1244C The Football Season
    Noip2016Day1T2 天天爱跑步
    Noip2015Day2T3 运输计划
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537844.html
Copyright © 2011-2022 走看看