Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 06 / Solutions / exercise04.cpp
diff options
context:
space:
mode:
1 files changed, 31 insertions, 0 deletions
-rw-r--r--Sem. 06/Solutions/exercise04.cpp31
diff --git a/Sem. 06/Solutions/exercise04.cpp b/Sem. 06/Solutions/exercise04.cpp
new file mode 100644
index 0000000..fa31c84
--- /dev/null
+++ b/Sem. 06/Solutions/exercise04.cpp
@@ -0,0 +1,31 @@
+#include <iostream>
+
+using namespace std;
+
+bool isPalindromeArray(int nums[], int len, int start) {
+ int end = (len - start) / 2;
+
+ for (int i = start; i < end; i++) {
+ if (nums[i] != nums[len - 1 - i])
+ return false;
+ }
+
+ return true;
+}
+
+int isConcatOfTwoPalindromes(int nums[], int len) {
+ int border = len / 2 + 1;
+
+ return isPalindromeArray(nums, border, 0) && isPalindromeArray(nums, len, border);
+}
+
+int main() {
+ int numbers1[9] = { 1, 2, 3, 2, 1, 4, 5, 5, 4 };
+ cout << isConcatOfTwoPalindromes(numbers1, 9) << endl;
+
+ int numbers2[5] = { 1, 2, 3, 4, 5 };
+ cout << isConcatOfTwoPalindromes(numbers2, 5) << endl;
+
+ int numbers3[5] = { 1, 2, 3, 2, 1 };
+ cout << isConcatOfTwoPalindromes(numbers3, 5) << endl;
+}