#include #include #include #include #include #include #include // this is a demonstration of the algorithms from the standard library int main() { std::vector numbers; // DONE: read a sequence of integers from stdin and store them in a vector // there is a twist: use std::copy, std::istream_iterator and std::back_inserter // // std::copy( std::istream_iterator(std::cin), std::istream_iterator(), // std::ostream_iterator(std::cout, " ") std::back_inserter(numbers) ); // DONE: print the numbers in the vector using std::copy, std::ostream_iterator and std::cout; separate the numbers with a newline // std::copy( numbers.cbegin(), numbers.cend(), std::ostream_iterator(std::cout, "\n") ); // DONE: sort the vector using std::sort; compare the numbers using std::greater (reverse order) std::sort(numbers.begin(), numbers.end(), std::greater()); // DONE: print the squares of the numbers in the vector using std::transform, std::ostream_iterator and std::cout; separate the numbers with a newline // use a lambda expression to square the numbers std::transform( numbers.cbegin(), numbers.cend(), std::ostream_iterator(std::cout, "\n"), [](int i) { return i * i; } ); // DONE: remove all the numbers that are divisible by 3 using std::remove_if and a subsequent std::vector::erase auto it = std::remove_if( numbers.begin(), numbers.end(), [](int i) { return i % 3 == 0; } ); numbers.erase(it, std::end(numbers)); // TODO: insert the numbers into a set using std::copy and std::inserter, you have to pass some iterator to the inserter (begin or end) as well // TODO: create a map that maps the numbers to their order in the set using std::transform, std::views::iota (creates a pseudo-container with a range of numbers), std::inserter and std::make_pair // auto order = std::views::iota(1); // contains 1, 2, ...; use order.begin() as the second begin to std::transform // TODO: print the pairs in the map using std::for_each and a lambda expression (it can take an `auto` parameter; use .first and .second to access the members) }