aboutsummaryrefslogtreecommitdiff
path: root/challenge-205/deadmarshal/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-205/deadmarshal/cpp')
-rw-r--r--challenge-205/deadmarshal/cpp/ch-1.cpp22
-rw-r--r--challenge-205/deadmarshal/cpp/ch-2.cpp24
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-205/deadmarshal/cpp/ch-1.cpp b/challenge-205/deadmarshal/cpp/ch-1.cpp
new file mode 100644
index 0000000000..e356586b2b
--- /dev/null
+++ b/challenge-205/deadmarshal/cpp/ch-1.cpp
@@ -0,0 +1,22 @@
+#include<iostream>
+#include<vector>
+#include<algorithm>
+
+template<typename T>
+int third_highest(std::vector<T> &vec)
+{
+ std::sort(vec.begin(),vec.end(),std::greater<T>());
+ vec.erase(std::unique(vec.begin(),vec.end()),vec.end());
+ if(vec.size() < 3) return vec[0];
+ return vec[2];
+}
+
+int main()
+{
+ std::vector<int> vec1{5,3,4},vec2{5,6},vec3{5,4,4,3};
+ std::cout << third_highest<int>(vec1) << '\n';
+ std::cout << third_highest<int>(vec2) << '\n';
+ std::cout << third_highest<int>(vec3) << '\n';
+ return 0;
+}
+
diff --git a/challenge-205/deadmarshal/cpp/ch-2.cpp b/challenge-205/deadmarshal/cpp/ch-2.cpp
new file mode 100644
index 0000000000..370398b4ca
--- /dev/null
+++ b/challenge-205/deadmarshal/cpp/ch-2.cpp
@@ -0,0 +1,24 @@
+#include<iostream>
+#include<vector>
+
+template<typename T>
+int maximum_xor(const std::vector<T> &vec)
+{
+ int max = 0;
+ for(size_t i = 0; i < vec.size(); ++i)
+ for(size_t j = 0; j < vec.size(); ++j)
+ {
+ int temp = vec[i] ^ vec[j];
+ if(max < temp) max = temp;
+ }
+ return max;
+}
+
+int main()
+{
+ std::cout << maximum_xor<int>({1,2,3,4,5,6,7}) << '\n';
+ std::cout << maximum_xor<int>({2,4,1,3}) << '\n';
+ std::cout << maximum_xor<int>({10,5,7,12,8}) << '\n';
+ return 0;
+}
+