• map-count


    ////////////////////////////////////////
    //      2018/05/01 14:14:57
    //      map-count
    
    // returns the number of elements
    
    #include <iostream>
    #include <map>
    #include <list>
    #include <numeric>
    
    using namespace std;
    
    int main(){
        list<int> L1(3), L2(3);
        iota(L1.begin(), L1.end(), 1);
        iota(L2.begin(), L2.end(), 4);
    
        typedef map<int, list<int>> M;
        M m;
        m.insert(M::value_type(1, L1));
        m.insert(M::value_type(2, L2));
    
        M::iterator it;
        list<int>::iterator Li;
    
        for (it = m.begin(); it != m.end(); it++){
            cout << "map " << it->first << ":";
            for (Li = it->second.begin(); Li != it->second.end(); Li++){
                cout << *Li << " ";
            }
            cout << endl;
        }
    
        int n = m.count(2);
        cout << "count of element with '2'(0 or 1) is "
            << n << endl;
        return 0;
    }
    
    /*
    OUTPUT:
        map 1:1 2 3
        map 2:4 5 6
        count of element with '2'(0 or 1) is 1
    */ 
  • 相关阅读:
    关于MySQL数据库中null的那些事
    Java集合之Collections 剖析
    字符串类
    C++标准库
    << 操作符
    操作符的重载
    类中的重载
    友元
    二阶构造模式
    静态成员函数
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537861.html
Copyright © 2020-2023  润新知