From 774e09abf3cc1ad99505fd415fe62fcb766d06e0 Mon Sep 17 00:00:00 2001 From: deadmarshal Date: Thu, 23 Feb 2023 14:48:33 +0330 Subject: TWC205 --- challenge-205/deadmarshal/cpp/ch-2.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 challenge-205/deadmarshal/cpp/ch-2.cpp (limited to 'challenge-205/deadmarshal/cpp/ch-2.cpp') 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 +#include + +template +int maximum_xor(const std::vector &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({1,2,3,4,5,6,7}) << '\n'; + std::cout << maximum_xor({2,4,1,3}) << '\n'; + std::cout << maximum_xor({10,5,7,12,8}) << '\n'; + return 0; +} + -- cgit