unordered_multimap count() function in C++ STL Last Updated : 28 Dec, 2022 Comments Improve Suggest changes Like Article Like Report The unordered_multimap::count() is a built-in function in C++ STL that returns the number of elements in the container whose key is equal to the key passed in the parameter. Syntax: unordered_multimap_name.count(key) Parameters: The function accepts a single mandatory parameter key that specifies the key whose count in the unordered_multimap container is to be returned. Return Value: It returns an unsigned integral type which denotes the number of times a key occurs in the container. Time Complexity: O(N) Below programs illustrates the above function: Program 1: CPP // C++ program to illustrate the // unordered_multimap::count() #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multimap<int, int> sample; // inserts key and element sample.insert({ 10, 100 }); sample.insert({ 10, 100 }); sample.insert({ 20, 200 }); sample.insert({ 30, 300 }); sample.insert({ 30, 150 }); cout << "10 occurs " << sample.count(10) << " times"; cout << "\n20 occurs " << sample.count(20) << " times"; cout << "\n13 occurs " << sample.count(13) << " times"; cout << "\n30 occurs " << sample.count(30) << " times"; return 0; } Output:10 occurs 2 times 20 occurs 1 times 13 occurs 0 times 30 occurs 2 times Program 2: CPP // C++ program to illustrate the // unordered_multimap::count() #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multimap<char, char> sample; // inserts key and element sample.insert({ 'a', 'b' }); sample.insert({ 'a', 'b' }); sample.insert({ 'b', 'c' }); sample.insert({ 'r', 'a' }); sample.insert({ 'r', 'b' }); cout << "a occurs " << sample.count('a') << " times"; cout << "\nb occurs " << sample.count('b') << " times"; cout << "\nz occurs " << sample.count('z') << " times"; cout << "\nr occurs " << sample.count('r') << " times"; return 0; } Output:a occurs 2 times b occurs 1 times z occurs 0 times r occurs 2 times Create Quiz Comment G gopaldave Follow 0 Improve G gopaldave Follow 0 Improve Article Tags : Misc C++ STL CPP-Functions cpp-unordered_multimap +1 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like