STL reverse in C++
Level 4198 keystrokes
Uses std::reverse to reverse a vector in place and then a string, printing "5 4 3 2 1" and "olleH".
C++ code
// Creates a vector with 1 to 5 in ascending order1vector<int> nums = {1, 2, 3, 4, 5};// Reverses the range [begin, end) in place, so nums becomes 5 4 3 2 12reverse(nums.begin(), nums.end());// Prints each element followed by a space: 5 4 3 2 13for (int n : nums) cout << n << " ";// Ends the first line4cout << endl;5 6string str = "Hello";// A string also has iterators, so reverse turns "Hello" into "olleH"7reverse(str.begin(), str.end());// Prints olleH8cout << str << endl;Output
5 4 3 2 1 olleH
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.
<× 11;× 7(× 7)× 7,× 6.× 4"× 4=× 2:× 1{× 1