blob: 470b53ed46d650fc4b191bbb067de5044477d9b5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include <iostream>
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;
}
|