-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11953.cpp
More file actions
37 lines (36 loc) · 841 Bytes
/
11953.cpp
File metadata and controls
37 lines (36 loc) · 841 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;
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
char a[200][200];
int N, M;
int call(int i, int j) {
if (i < 0 || j < 0 || i >= N || j >= N) return 0;
if (a[i][j] == '.') return 0;
a[i][j] = '.';
for (int k = 0; k < 4; k++) {
call(i + dx[k], j + dy[k]);
}
return 0;
}
int main() {
int n, m, tc, t = 1;
cin >> tc;
while (tc--) {
scanf("%d", &n);
getchar();
N = n;
for (int i = 0; i < n; i++) gets(a[i]);
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 'x') {
call(i, j);
count++;
}
}
}
printf("Case %d: %d\n", t++, count);
}
return 0;
}