Website Summary Files Commits Branches @commit @diff @stats
path: root / Week10 / Exercise12.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/Exercise12.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, 52 insertions, 0 deletions
-rw-r--r--Week10/Exercise12.cpp52
diff --git a/Week10/Exercise12.cpp b/Week10/Exercise12.cpp
new file mode 100644
index 0000000..38bf452
--- /dev/null
+++ b/Week10/Exercise12.cpp
@@ -0,0 +1,52 @@
+#include <iostream>
+
+int main() {
+ unsigned int count = 0, allocated = 4;
+ int* indecies = new int[allocated];
+ double* values = new double[allocated];
+
+ int index;
+ std::cin >> index;
+ while (index >= 0) {
+ indecies[count] = index;
+ std::cin >> values[count++];
+
+ if (count >= allocated) {
+ allocated *= 2;
+ int* newIndecies = new int[allocated];
+ double* newValues = new double[allocated];
+
+ for (unsigned int i = 0; i < count; i++) {
+ newIndecies[i] = indecies[i];
+ newValues[i] = values[i];
+ }
+
+ delete[] indecies;
+ delete[] values;
+
+ indecies = newIndecies;
+ values = newValues;
+ }
+
+ std::cin >> index;
+ }
+
+ std::cin >> index;
+ bool printed = false;
+
+ for (unsigned int i = 0; i < count; i++) {
+ if (indecies[i] == index) {
+ std::cout << values[i] << std::endl;
+ printed = true;
+ break;
+ }
+ }
+
+ if (!printed)
+ std::cout << 0 << std::endl;
+
+ delete[] indecies;
+ delete[] values;
+
+ return 0;
+}