Set container in C++
Level 4194 keystrokes
Inserts numbers into a set, which ignores duplicates and keeps elements sorted, then prints its size 3, the elements 1 3 5 and count(3), which is 1.
C++ code
// A set holds unique values in sorted order1set<int> nums;2nums.insert(5);3nums.insert(3);// 5 is already present, so this insert does nothing4nums.insert(5);5nums.insert(1);6 // Three distinct values: prints 37cout << nums.size() << endl;// Iteration is in ascending order: 1 3 58for (int n : nums) {9 cout << n << " ";10}11cout << endl;// count returns 1 if the value is in the set, otherwise 0: prints 112cout << nums.count(3) << endl;Output
3 1 3 5 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.
<× 15;× 9(× 7)× 7.× 6"× 2:× 1{× 1}× 1>× 1