aboutsummaryrefslogtreecommitdiff
path: root/challenge-199/deadmarshal/cpp/ch-1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-199/deadmarshal/cpp/ch-1.cpp')
-rw-r--r--challenge-199/deadmarshal/cpp/ch-1.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-199/deadmarshal/cpp/ch-1.cpp b/challenge-199/deadmarshal/cpp/ch-1.cpp
new file mode 100644
index 0000000000..b5ccda1df0
--- /dev/null
+++ b/challenge-199/deadmarshal/cpp/ch-1.cpp
@@ -0,0 +1,22 @@
+#include<iostream>
+#include<vector>
+
+template<typename T>
+int good_pairs(const std::vector<T> &vec)
+{
+ int count{};
+ for(size_t i = 0; i < vec.size(); ++i)
+ for(size_t j = i+1; j < vec.size(); ++j)
+ if(vec[i] == vec[j]) count++;
+ return count;
+}
+
+int main()
+{
+ std::vector<int> vec1{1,2,3,1,1,3},vec2{1,2,3},vec3{1,1,1,1};
+ std::cout << good_pairs<int>(vec1) << '\n';
+ std::cout << good_pairs<int>(vec2) << '\n';
+ std::cout << good_pairs<int>(vec3) << '\n';
+ return 0;
+}
+