• multimap-find


    ////////////////////////////////////////
    //      2018/05/04 17:04:52
    //      multimap-find
    
    // finds a given element
    #include <iostream>
    #include <map>
    
    using namespace std;
    
    int main(){
        typedef multimap<int, char> M;
        typedef M::value_type v_t;
        char ch = 'A';
        M m;
    
        for (int i = 0; i < 5; i++){
            m.insert(v_t(i++,ch++));
        }
        m.insert(v_t(4,'F'));
    
        M::iterator it = m.begin();
        cout << "multimap m:" << endl;
    
        while (it != m.end()){
            cout << it->first << "-" << it->second << endl;
            it++;
        }
    
        it = m.find(4);
        if (it != m.end()){
            cout << "element key '4' has value" << it->second << endl;
        }else{
            cout << "element key '4' not found." << endl;
        }
    
        M::iterator upp = m.upper_bound(4);
        cout << "all elements with key '4'" << endl;
        while (it != upp){
            cout << it->first << "-" << it->second << endl;
            it++;
        }
    
        return 0;
    }
    
    
    /*
    OUTPUT:
        multimap m:
        0-A
        2-B
        4-C
        4-F
        element key '4' has valueC
        all elements with key '4'
        4-C
        4-F
    */ 
  • 相关阅读:
    Subsets
    Search a 2D Matrix II
    Search a 2D Matrix
    Search Insert Position
    Search for a Range
    Sort Colors
    Sort List
    语音笔记04-3 TEHO,COR
    语音笔记04-2 拨号规则
    语音笔记04-1 CME实验
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537832.html
Copyright © 2020-2023  润新知