Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Solutions Sem. 06 / exercise04.cpp
diff options
context:
space:
mode:
Commitd6e6b0328ce2a4fe228262713e89e391421f5ab3 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-17 09:26:15 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-11-17 09:26:15 +0200
Files3ae1ab57c1cfc722fc24a26e2e0d2c403b8527d4 /Year 1/Programming introduction/Solutions Sem. 06/exercise04.cpp
uni-projects-d6e6b0328ce2a4fe228262713e89e391421f5ab3.tar
uni-projects-d6e6b0328ce2a4fe228262713e89e391421f5ab3.tar.gz
uni-projects-d6e6b0328ce2a4fe228262713e89e391421f5ab3.zip
Parentb02c6e3dc1917eedf2791bd89b9e3c80e6f1ef9f (diff)
Added my solutions to Sem. 06 exercises
1 files changed, 31 insertions, 0 deletions
-rw-r--r--Year 1/Programming introduction/Solutions Sem. 06/exercise04.cpp31
diff --git a/Year 1/Programming introduction/Solutions Sem. 06/exercise04.cpp b/Year 1/Programming introduction/Solutions Sem. 06/exercise04.cpp
new file mode 100644
index 0000000..fa31c84
--- /dev/null
+++ b/Year 1/Programming introduction/Solutions Sem. 06/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;
+}