diff --git a/2024/07/cpp_algorithms1/.gitignore b/2024/07/cpp_algorithms1/.gitignore new file mode 100644 index 0000000..be13b48 --- /dev/null +++ b/2024/07/cpp_algorithms1/.gitignore @@ -0,0 +1 @@ +cmake-build* \ No newline at end of file diff --git a/2024/07/cpp_algorithms1/CMakeLists.txt b/2024/07/cpp_algorithms1/CMakeLists.txt new file mode 100644 index 0000000..ee63337 --- /dev/null +++ b/2024/07/cpp_algorithms1/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.28) +project(cpp_algorithms1) + +set(CMAKE_CXX_STANDARD 17) + +add_executable(cpp_algorithms1 main.cpp) diff --git a/2024/07/cpp_algorithms1/main.cpp b/2024/07/cpp_algorithms1/main.cpp new file mode 100644 index 0000000..0fb279e --- /dev/null +++ b/2024/07/cpp_algorithms1/main.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +int main() { + std::cout << "Hello, World!" << std::endl; + + std::vector numbers = {1, 2, -1, 3, -2, 4}; + + numbers.erase(std::remove_if( + numbers.begin(), + numbers.end(), + [](int x) { return x < 0; }), + numbers.end()); + + auto sum = 0; + for (auto it = numbers.begin(); it != numbers.end(); it++) { + sum += *it; + } + + std::cout << "Sum is: " << sum << "." << std::endl; + + sum = 0; + + auto res = std::accumulate( + numbers.begin(), + numbers.end(), + 1, + [](int a, int b) { return a * b; }); + + std::cout << "Multiplication is: " << res << "." << std::endl; + + return 0; +}