From 5294e73a21f3402e14fcf3379c721275e2dd19c2 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 23 Nov 2025 15:25:29 +0200 Subject: feat(Week08): Add solutions --- Week08/Exercise09.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Week08/Exercise09.cpp (limited to 'Week08/Exercise09.cpp') diff --git a/Week08/Exercise09.cpp b/Week08/Exercise09.cpp new file mode 100644 index 0000000..4753903 --- /dev/null +++ b/Week08/Exercise09.cpp @@ -0,0 +1,36 @@ +#include + +int main() { + const unsigned int ROWS = 4, COLS = 3; + char keypad[ROWS][COLS] = { + '1', '2', '3', + '4', '5', '6', + '7', '8', '9', + '*', '0', '#', + }; + + bool rowOn[ROWS]; + for (unsigned int i = 0; i < ROWS; i++) + std::cin >> rowOn[i]; + + bool colOn[COLS]; + for (unsigned int i = 0; i < COLS; i++) + std::cin >> colOn[i]; + + bool somethingPressed = false; + for (unsigned int row = 0; row < ROWS; row++) { + for (unsigned int col = 0; col < COLS; col++) { + if (rowOn[row] && colOn[col]) { + std::cout << keypad[row][col] << ' '; + somethingPressed = true; + } + } + } + + if (!somethingPressed) + std::cout << "Nothing pressed"; + + std::cout << std::endl; + + return 0; +} -- cgit v1.3.1-23-gd82d