Website Summary Files Commits Branches @commit @diff @stats
path: root / Week10 / Exercise03.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/Exercise03.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, 38 insertions, 0 deletions
-rw-r--r--Week10/Exercise03.cpp38
diff --git a/Week10/Exercise03.cpp b/Week10/Exercise03.cpp
new file mode 100644
index 0000000..5815b58
--- /dev/null
+++ b/Week10/Exercise03.cpp
@@ -0,0 +1,38 @@
+#include <iostream>
+
+int main() {
+ unsigned int rows, cols;
+ std::cin >> rows >> cols;
+
+ unsigned int** mat = new unsigned int*[rows];
+ for (unsigned int row = 0; row < rows; row++) {
+ mat[row] = new unsigned int[cols];
+
+ for (unsigned int col = 0; col < cols; col++)
+ std::cin >> mat[row][col];
+ }
+
+ /* По принцип можем да решим задачата, все едно е динамична памет,
+ * тоест да разменяме първи елемент от първи ред с първи от последен
+ * ред, втори от първи ред с втори от последен ред и так. нат.
+ *
+ * Но тук, по-простия начин е да разменим указатели, което също е по-ефикасно.
+ */
+ for (unsigned int row = 0; row < rows / 2; row++) {
+ unsigned int* temp = mat[row];
+ mat[row] = mat[rows - 1 - row];
+ mat[rows - 1 - row] = temp;
+ }
+
+ for (unsigned int row = 0; row < rows; row++) {
+ for (unsigned int col = 0; col < cols; col++)
+ std::cout << mat[row][col] << ' ';
+ std::cout << std::endl;
+ }
+
+ for (unsigned int row = 0; row < rows; row++)
+ delete[] mat[row];
+ delete[] mat;
+
+ return 0;
+}