/
SWAcademy 7236
56 lines (48 loc) · 1.27 KB
/
SWAcademy 7236
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
static String[][] arr;
static int[][] map;
static int[] dy = { -1, 1, 0, 0, -1, -1, 1, 1 }, dx = { 0, 0, -1, 1, 1, -1, 1, -1 };
static int N, ans;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
N = Integer.parseInt(br.readLine());
arr = new String[N][N];
map = new int[N][N];
ans = 0;
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 0; j < N; j++) {
arr[i][j] = st.nextToken();
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
check(i, j);
}
}
ans = map[0][0];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (map[i][j] > ans)
ans = map[i][j];
}
}
System.out.println("#" + t + " " + ans);
}
}
private static void check(int y, int x) {
for (int i = 0; i < 8; i++) {
int ny = y + dy[i];
int nx = x + dx[i];
if (ny < 0 || nx < 0 || ny >= N || nx >= N)
continue;
if(arr[ny][nx].equals("W"))
map[y][x]++;
}
}
}