SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.io.*;
import java.util.*;
public class Main {
static int N;
static char[][] reservoir;
static int[] dr = {-1, -1, -1, 0, 0, 1, 1, 1};
static int[] dc = {-1, 0, 1, -1, 1, -1, 0, 1};
public static int getDepth (int row, int column) {
int wCnt = 0;
for (int d = 0; d < 8; d++)
if (row+dr[d] >= 0 && row+dr[d] < N && column+dc[d] >= 0 && column+dc[d] < N && reservoir[row+dr[d]][column+dc[d]] == 'W') wCnt++;
if (wCnt == 0) return 1;
else return wCnt;
}
public static void main (String[] args) throws IOException {
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()); // 저수지 구획 크기
reservoir = new char[N][N];
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for (int j = 0; j < N; j++)
reservoir[i][j] = st.nextToken().charAt(0);
}
int maxDepth = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) maxDepth = Math.max(maxDepth, getDepth(i, j));
System.out.println("#" + t + " " + maxDepth);
}
}
}
'Algorithm > 백준+프로그래머스+SWEA+정올+구름' 카테고리의 다른 글
[Algorithm] SWEA 5356 의석이의 세로로 말해요 (0) | 2021.08.27 |
---|---|
[Algorithm] 백준 12927 배수 스위치 (0) | 2021.08.27 |
[Algorithm] SWEA 2805 농작물 수확하기 (0) | 2021.08.26 |
[Algorithm] 백준 2999 비밀 이메일 (0) | 2021.08.25 |
[Algorithm] 백준 2941 크로아티아 알파벳 (0) | 2021.08.25 |