aboutsummaryrefslogtreecommitdiff
path: root/challenge-199/deadmarshal/cpp/ch-1.cpp
diff options
context:
space:
mode:
authorBob Lied <boblied+github@gmail.com>2023-01-14 06:30:38 -0600
committerGitHub <noreply@github.com>2023-01-14 06:30:38 -0600
commita2fcd3539045b5ff54ea81bc6cbec004c0f1fea7 (patch)
tree2891d52ef32c29b32d1b6ee5e40f879c74e1bd18 /challenge-199/deadmarshal/cpp/ch-1.cpp
parent060e309523bbbf50e6cb9684d858e7059344f31b (diff)
parent70a1571ce4c48f53a1eebc84eddb5c035f88b987 (diff)
downloadperlweeklychallenge-club-a2fcd3539045b5ff54ea81bc6cbec004c0f1fea7.tar.gz
perlweeklychallenge-club-a2fcd3539045b5ff54ea81bc6cbec004c0f1fea7.tar.bz2
perlweeklychallenge-club-a2fcd3539045b5ff54ea81bc6cbec004c0f1fea7.zip
Merge branch 'manwar:master' into master
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;
+}
+