Beispiellösung

Content

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <numeric>
#include <random>
#include <vector>

struct IsIncreasing {
   bool operator()(const int& value) {
      if (value >= last_selected_value) {
	 last_selected_value = value;
	 return true;
      } else {
	 return false;
      }
   }
   int last_selected_value = std::numeric_limits<int>::min();
};

int main() {
   /* initialize values and fill it with shuffled values 1..100 */
   std::vector<int> values(100);
   std::iota(values.begin(), values.end(), 1);
   std::shuffle(values.begin(), values.end(), std::mt19937(2));

   /* select all even values out of it */
   std::vector<int> selected_values;
   std::copy_if(values.begin(), values.end(),
      std::back_inserter(selected_values), IsIncreasing());

   /* print selected values */
   int count = 0;
   for (auto value: selected_values) {
      std::cout << std::setw(4) << value;
      if (++count % 10 == 0) std::cout << std::endl;
   }
   std::cout << std::endl;
}
theon$ g++ -Wall -o select-increasing select-increasing.cpp
theon$ ./select-increasing
   6  20  88  93  97  98  99 100
theon$