-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva10855.cpp
More file actions
88 lines (75 loc) · 2.06 KB
/
uva10855.cpp
File metadata and controls
88 lines (75 loc) · 2.06 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<sstream>
#include<cstdio>
using namespace std;
typedef long long ll;
void rotate(vector<string>& block) {
int n = block.size();
for (int i = 0; i< n/2; i++) {
for(int j = i ; j < n - i - 1; j++) { //Can reduce the tmp variables but this is clearer
char top, right, bottom, left;
top = block[i][j];
right = block[j][n-i-1];
bottom = block[n-i-1][n-j-1];
left = block[n-j-1][i];
block[i][j] = left;
block[j][n-i-1]= top;
block[n-i-1][n-j-1]=right;
block[n-j-1][i]=bottom;
}
}
}
int countMatches(vector<string>& large, vector<string>& small) {
int ls = large.size(), ss = small.size();
int answer = 0;
for (int i = 0; i <= ls -ss; i++) {
for (int j = 0; j <= ls - ss; j++) {
bool match = true;
for(int u =0; u < ss; u++) {
for (int v=0; v< ss; v++) {
if (large[i+u][j+v] != small[u][v]) {
match = false;
break;
}
}
if (not match)
break;
}
if (match)
answer++;
}
}
return answer;
}
int main() {
while (true) {
vector<string> large, small;
string s;
int n, N, r[4];
istringstream iss;
//scanf("%d %d\n", &N, &n);
getline(cin, s);
iss = istringstream(s);
iss >> N >>n;
if (N==0)
break;
for (int i = 0; i < N; i++) {
getline(cin, s);
large.push_back(s);
}
for (int i = 0; i < n; i++) {
getline(cin, s);
small.push_back(s);
}
n = n;
for(int i = 0; i < 4; i++) {
r[i] = countMatches(large, small);
rotate(small);
}
cout << r[0] << " "<< r[1] << " "<< r[2] << " "<< r[3] << "\n";
}
}