-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchess_board.cpp
More file actions
86 lines (70 loc) · 1.51 KB
/
chess_board.cpp
File metadata and controls
86 lines (70 loc) · 1.51 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
#include <iostream>
using namespace std;
char toggle_put(void);
char map[50][50];
char mask_1[8][8];
char mask_2[8][8];
int toggle = 1;
int main(void){
int i, j;
int n, m;
cin >> n >> m;
for(i = 0; i < n; i++){
for(j = 0; j < m; j++){
cin >> map[i][j];
}
}
for(i = 0; i < 8; i++){
for(j = 0; j < 8; j++){
mask_1[i][j] = toggle_put();
}
toggle_put();
}
toggle_put();
for(i = 0; i < 8; i++){
for(j = 0; j < 8; j++){
mask_2[i][j] = toggle_put();
}
toggle_put();
}
int a = 0;
int b = 0;
int count_1 = 0;
int count_2 = 0;
int min = 64;
while (a < n - 7){
while(b < m - 7){
for(i = a; i < a + 8; i++){
for(j = b; j < b + 8; j++){
if(mask_1[i-a][j-b] != map[i][j]){
count_1++;
}
if(mask_2[i-a][j-b] != map[i][j]){
count_2++;
}
}
}
if(min > count_1){
min = count_1;
}
if(min > count_2){
min = count_2;
}
count_1 = 0;
count_2 = 0;
b++;
}
b = 0;
a++;
}
cout << min << endl;
}
char toggle_put(void){
if(toggle){
toggle = 0;
return 'W';
} else {
toggle = 1;
return 'B';
}
}