From 7d92a145e089e59f0f830843ba91cd7223bc6c98 Mon Sep 17 00:00:00 2001 From: deadmarshal Date: Wed, 15 Nov 2023 21:53:10 +0330 Subject: TWC243 extra solutions --- challenge-243/deadmarshal/cpp/ch-2.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 challenge-243/deadmarshal/cpp/ch-2.cpp (limited to 'challenge-243/deadmarshal/cpp/ch-2.cpp') diff --git a/challenge-243/deadmarshal/cpp/ch-2.cpp b/challenge-243/deadmarshal/cpp/ch-2.cpp new file mode 100644 index 0000000000..91ab6afe0b --- /dev/null +++ b/challenge-243/deadmarshal/cpp/ch-2.cpp @@ -0,0 +1,21 @@ +#include +#include + +template +std::size_t floor_sum(const std::vector &vec) +{ + std::size_t sum{}; + for(std::size_t i{}; i < vec.size(); ++i) + for(std::size_t j{}; j < vec.size(); ++j) + sum += static_cast(vec.at(i) / vec.at(j)); + return sum; +} + +int main() +{ + std::vector vec1{2,5,9},vec2{7,7,7,7,7,7,7}; + std::cout << floor_sum(vec1) << '\n' + << floor_sum(vec2) << '\n'; + return 0; +} + -- cgit