Unordered set in C++
Level 3133 keystrokes
unordered_set stores unique values in a hash table, so lookups are fast on average but the elements have no defined order. After inserting "bird" it has 3 elements, and count("cat") is 1.
C++ code
// A hash-based set: unique values, no guaranteed order1unordered_set<string> words = {"cat", "dog"};// Adds "bird"; inserting a value that already exists would change nothing2words.insert("bird");// cat, dog and bird: prints 33cout << words.size() << endl;// count is 1 if the value is present and 0 if not: prints 14cout << words.count("cat") << endl;Output
3 1
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"× 8;× 4.× 3(× 3)× 3_× 1,× 1{× 1}× 1