Website Summary Files Commits Branches @commit @diff @stats
path: root / Week08 / Exercise15.cpp
diff options
context:
space:
mode:
Commit5294e73a21f3402e14fcf3379c721275e2dd19c2 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-11-23 15:25:29 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-11-23 16:05:21 +0200
Files3f02cc12e0868ac043d7f937fec380b29f54c71a /Week08/Exercise15.cpp
upp-2025-solutions-5294e73a21f3402e14fcf3379c721275e2dd19c2.tar
upp-2025-solutions-5294e73a21f3402e14fcf3379c721275e2dd19c2.tar.gz
upp-2025-solutions-5294e73a21f3402e14fcf3379c721275e2dd19c2.zip
Parent3e8ac7ba4a8f410703aa5a8426f542217adcbf2f (diff)
feat(Week08): Add solutions
1 files changed, 48 insertions, 0 deletions
-rw-r--r--Week08/Exercise15.cpp48
diff --git a/Week08/Exercise15.cpp b/Week08/Exercise15.cpp
new file mode 100644
index 0000000..fba54ff
--- /dev/null
+++ b/Week08/Exercise15.cpp
@@ -0,0 +1,48 @@
+#include <iostream>
+
+const int ROWS = 9, COLS = 7;
+
+int max(int a, int b) {
+ return a > b ? a : b;
+}
+
+int min(int a, int b) {
+ return a < b ? a : b;
+}
+
+double abs(double x) {
+ return x < 0 ? -x : x;
+}
+
+bool checkSurroundingCells(const double mat[ROWS][COLS], int row, int col, double maxDiff)
+{
+ for (int r = max(0, row - 1); r <= min(ROWS - 1, row + 1); r++) {
+ for (int c = max(0, col - 1); c <= min(COLS - 1, col + 1); c++) {
+ if (abs(mat[r][c] - mat[row][col]) >= maxDiff)
+ return false;
+ }
+ }
+ return true;
+}
+
+int main() {
+ double mat[ROWS][COLS];
+ for (int i = 0; i < ROWS; i++)
+ for (int j = 0; j < COLS; j++)
+ std::cin >> mat[i][j];
+
+ double maxDiff;
+ std::cin >> maxDiff;
+
+ bool smooth = true;
+ for (int i = 0; i < ROWS && smooth; i++)
+ for (int j = 0; j < COLS && smooth; j++)
+ smooth = checkSurroundingCells(mat, i, j, maxDiff);
+
+ if (smooth)
+ std::cout << "Smooth" << std::endl;
+ else
+ std::cout << "Not smooth" << std::endl;
+
+ return 0;
+}