unordered_multimap::count()
描述 (Description)
C ++函数std::unordered_multimap::count()返回与密钥k关联的映射值的数量。
声明 (Declaration)
以下是std :: unordered_multimap :: count()函数形式std :: unordered_map()头的声明。
C++11
size_type count(const key_type& k) const;
参数 (Parameters)
k - 搜索操作的键。
返回值
返回与key关联的值的数量。
时间复杂
线性即O(n)
例子 (Example)
以下示例显示了std :: unordered_multimap :: count()函数的用法。
#include <iostream>
#include <unordered_map>
using namespace std;
int main(void) {
unordered_multimap<char, int> umm = {
{'a', 1},
{'a', 2},
{'b', 3},
{'b', 4},
{'c', 5}
};
cout << "Count of a = " << umm.count('a') << endl;
cout << "Count of b = " << umm.count('b') << endl;
cout << "Count of c = " << umm.count('c') << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Count of a = 2
Count of b = 2
Count of c = 1