diff options
Diffstat (limited to 'challenge-243/deadmarshal/cpp/ch-1.cpp')
| -rw-r--r-- | challenge-243/deadmarshal/cpp/ch-1.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-243/deadmarshal/cpp/ch-1.cpp b/challenge-243/deadmarshal/cpp/ch-1.cpp new file mode 100644 index 0000000000..1400521502 --- /dev/null +++ b/challenge-243/deadmarshal/cpp/ch-1.cpp @@ -0,0 +1,21 @@ +#include<iostream> +#include<vector> + +template<typename T> +std::size_t reverse_pairs(const std::vector<T> &vec) +{ + std::size_t count{}; + for(std::size_t i = 0; i < vec.size()-1; ++i) + for(std::size_t j = i+1; j < vec.size(); ++j) + if(vec.at(i) > (2 * vec.at(j))) count++; + return count; +} + +int main() +{ + std::vector<int> vec1{1,3,2,3,1},vec2{2,4,3,5,1}; + std::cout << reverse_pairs<int>(vec1) << '\n' + << reverse_pairs<int>(vec2) << '\n'; + return 0; +} + |
