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

    ////////////////////////////////////////
    //      2018/05/04 9:56:28
    //      multimap-erase
    
    // removes elements
    #include <iostream>
    #include <map>
    #include <string>
    
    using namespace std;
    
    typedef multimap<string, int, less<string>>  M;
    
    void print(M& m){
        M::iterator it = m.begin();
        cout << "multimap:" << endl;
        while (it != m.end()){
            cout << it->first << "-" << it->second << endl;
            it++;
        }
    }
    //========================
    int main(){
    
        typedef M::value_type v_t;
        M m;
    
        m.insert(v_t("AAA",1));
        m.insert(v_t("BBB",2));
        m.insert(v_t("CCC",3));
        m.insert(v_t("EEE",4));
        m.insert(v_t("CCC",5));
        m.insert(v_t("DDD",6));
    
        print(m);
    
        M::iterator it;
        it = m.find("DDD");
        // remove element pointed by it
        m.erase(it);
        print(m);
    
        it = m.find("CCC");
        // remove the range of elements
        m.erase(m.begin(), it);
        print(m);
    
        return 0;
    }
    
    /*
    OUTPUT:
        multimap:
        AAA-1
        BBB-2
        CCC-3
        CCC-5
        DDD-6
        EEE-4
        multimap:
        AAA-1
        BBB-2
        CCC-3
        CCC-5
        EEE-4
        multimap:
        CCC-3
        CCC-5
        EEE-4
    */ 
  • 相关阅读:
    Muddy Fields
    LightOJ 1321
    LightOJ 1085
    LightOJ 1278
    LightOJ 1341
    LightOJ 1340
    vijos 1426 背包+hash
    vijos 1071 01背包+输出路径
    vijos 1907 DP+滚动数组
    vijos 1037 背包+标记
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537834.html
Copyright © 2011-2022 走看看