본문으로 바로가기

https://swexpertacademy.com/main/code/userProblem/userProblemDetail.do?contestProbId=AWlTKTUqCN8DFAVS&categoryId=AWlTKTUqCN8DFAVS&categoryType=CODE 

 

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);
        }
    }
}