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