stlalgorithms

STL Algorithms exercises

Exercise 1

  1. Create a sequence containing 1, 50, 3, 9, 18
  2. Use find_if to locate the fist element divisible by 5

Exercise 2

  1. Create a string containing "algorithms are fun"
  2. Use search to locate the sub string "are" and print its starting position

Exercise 3

  1. Create a sequence containing 1, 200, 5, 7, 900
  2. Use copy_if to copy all elements >100 to another sequence
  3. Use copy to the output stream to print the result

Exercise 4

  1. Create a sequnce containing 2,3,4,5
  2. Use transform to double each value in the sequence and store in another sequnce
  3. Print the result

Exercise 5

  1. Create a string containing "aaccdffgfgfgiili"
  2. Use sort, unique and string erase to get "acdfgil"

Exercise 6

  1. Create a sequence containing 1,500,345,6,3,6
  2. Use stable_partition to get 500,345,1,6,3,6

Exercise 7

  1. Create a sequence containing 1,500,345,6,3,6
  2. Use count_if to calculate number of elements >100