-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path352.cpp
More file actions
37 lines (35 loc) · 883 Bytes
/
352.cpp
File metadata and controls
37 lines (35 loc) · 883 Bytes
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
#include <bits/stdc++.h>
using namespace std;
char a[200][200];
int N;
int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void call(int i, int j) {
if (i < 0 || j < 0 || i >= N || j >= N) return;
if (a[i][j] != '1') return;
a[i][j] = '0';
for (int k = 0; k < 8; k++) {
call(i + dirx[k], j + diry[k]);
}
return;
}
int main() {
int total = 1;
while (scanf("%d", &N) == 1) {
getchar();
for (int k = 0; k < N; k++) {
scanf("%s", &a[k]);
}
int sum = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (a[i][j] == '1') {
sum++;
call(i, j);
}
}
}
printf("Image number %d contains %d war eagles.\n", total++, sum);
}
return 0;
}