Unordered map in C++
Level 3130 keystrokes
unordered_map stores key-value pairs in a hash table, giving fast lookups on average but no defined order. Prints Alice's value (25) and the number of entries (2).
C++ code
// Like map, but hash-based: keys are not kept in sorted order1unordered_map<string, int> ages;// [] inserts the key if it is missing and assigns the value2ages["Alice"] = 25;3ages["Bob"] = 30;// Average constant-time lookup: prints 254cout << ages["Alice"] << endl;// Two entries: prints 25cout << ages.size() << endl;Output
25 2
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 9"× 6;× 5[× 3]× 3=× 2_× 1,× 1.× 1(× 1