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/Exercise07.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Week08/Exercise07.cpp (limited to 'Week08/Exercise07.cpp') diff --git a/Week08/Exercise07.cpp b/Week08/Exercise07.cpp new file mode 100644 index 0000000..470b53e --- /dev/null +++ b/Week08/Exercise07.cpp @@ -0,0 +1,45 @@ +#include + +const unsigned int SIZE_PAT = 3; + +bool matchesPattern(const char pattern[SIZE_PAT][SIZE_PAT], const char* input, unsigned int inputRows, unsigned int inputCols) { + for (unsigned int i = 0; i < SIZE_PAT; i++) { + for (unsigned int j = 0; j < SIZE_PAT; j++) { + /* За повече информация защо така индексираме в input, вижте + * https://syndamia.com/teaching/upp-2025/cpp-pitfalls/#-int73-vs-int3-vs-int + */ + if (pattern[i][j] != '*' && pattern[i][j] != input[i * inputRows + j]) + return false; + } + } + return true; +} + +int main() { + char pattern[SIZE_PAT][SIZE_PAT]; + + for (unsigned int i = 0; i < SIZE_PAT; i++) + for (unsigned int j = 0; j < SIZE_PAT; j++) + std::cin >> pattern[i][j]; + + const unsigned int SIZE = 6; + char inp[SIZE][SIZE]; + + for (unsigned int i = 0; i < SIZE; i++) + for (unsigned int j = 0; j < SIZE; j++) + std::cin >> inp[i][j]; + + unsigned int matches = 0; + for (unsigned int i = 0; i <= SIZE - SIZE_PAT; i++) { + for (unsigned int j = 0; j <= SIZE - SIZE_PAT; j++) { + /* За повече информация защо подаваме такива стойности на функцията, + * вижте решението на 3та задача. + */ + matches += matchesPattern(pattern, (const char*)inp + i * SIZE + j, SIZE, SIZE); + } + } + + std::cout << matches << std::endl; + + return 0; +} -- cgit v1.3.1-23-gd82d