Website Summary Files Commits Branches @commit @diff @stats
path: root / Week10 / Exercise08.cpp
diff options
context:
space:
mode:
Commit5ce214686e668bf185222b518b78d7f47a20b4fd (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-12-07 13:44:16 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-12-07 13:44:16 +0200
Filesacd2c1e0f3f0c7aa850878a12a9b674b8be1ccf7 /Week10/Exercise08.cpp
upp-2025-solutions-5ce214686e668bf185222b518b78d7f47a20b4fd.tar
upp-2025-solutions-5ce214686e668bf185222b518b78d7f47a20b4fd.tar.gz
upp-2025-solutions-5ce214686e668bf185222b518b78d7f47a20b4fd.zip
Parent6f894be622e8046f43a70e843cff7bd99c58a3c1 (diff)
feat(Week10): Add solutions
1 files changed, 50 insertions, 0 deletions
-rw-r--r--Week10/Exercise08.cpp50
diff --git a/Week10/Exercise08.cpp b/Week10/Exercise08.cpp
new file mode 100644
index 0000000..3d558e1
--- /dev/null
+++ b/Week10/Exercise08.cpp
@@ -0,0 +1,50 @@
+#include <iostream>
+
+void resizeArray(int*& arr, unsigned int& size) {
+ int* newArr = new int[size * 2];
+ for (unsigned int i = 0; i < size; i++)
+ newArr[i] = arr[i];
+
+ delete[] arr;
+ arr = newArr;
+ size *= 2;
+}
+
+int main() {
+ unsigned int countA = 0, sizeA = 4, countB = 0, sizeB = 4;
+ int* arrA = new int[sizeA], *arrB = new int[sizeB];
+
+ bool even = true;
+ int temp;
+ std::cin >> temp;
+
+ while (temp > 0) {
+ if (even) {
+ arrA[countA++] = temp;
+ if (countA >= sizeA)
+ resizeArray(arrA, sizeA);
+ }
+ else {
+ arrB[countB++] = temp;
+ if (countB >= sizeB)
+ resizeArray(arrB, sizeB);
+ }
+
+ even = !even;
+ std::cin >> temp;
+ }
+
+ unsigned int count = (countA > countB) ? countA : countB;
+ for (unsigned int i = 0; i < count; i++) {
+ if (i < countB)
+ std::cout << arrB[countB - 1 - i] << ' ';
+ if (i < countA)
+ std::cout << arrA[i] << ' ';
+ }
+ std::cout << std::endl;
+
+ delete[] arrA;
+ delete[] arrB;
+
+ return 0;
+}