aboutsummaryrefslogtreecommitdiff
path: root/challenge-199/deadmarshal/cpp/ch-1.cpp
diff options
context:
space:
mode:
authordeadmarshal <adeadmarshal@gmail.com>2023-01-10 13:03:07 +0330
committerdeadmarshal <adeadmarshal@gmail.com>2023-01-10 13:03:07 +0330
commit0e3e1a42869013d09eaa4c797cd957539004d944 (patch)
treeb2bd4f49bb2d5dd3eccb3bb8c7bc57575a8787e7 /challenge-199/deadmarshal/cpp/ch-1.cpp
parentb8a1cd65abd85f6cf9df5b9dc5bc34677763b531 (diff)
downloadperlweeklychallenge-club-0e3e1a42869013d09eaa4c797cd957539004d944.tar.gz
perlweeklychallenge-club-0e3e1a42869013d09eaa4c797cd957539004d944.tar.bz2
perlweeklychallenge-club-0e3e1a42869013d09eaa4c797cd957539004d944.zip
TWC199
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;
+}
+