본문으로 바로가기

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXaSUPYqPYMDFASQ 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 


 

import java.io.*;

public class Solution {
	
	static int N;
	static char[][] stage;
	
	static int[] dc = {1, 1, 0, -1};
	static int[] dr = {0, 1, 1, 1};
	
	public static boolean checkO (int i, int j) {
		for (int d = 0; d < 4; d++) {
			for (int k = 1; k <= 4; k++) {
				if (!(i+dr[d]*k >= 0 && i+dr[d]*k < N && j+dc[d]*k >= 0 && j+dc[d]*k < N  && stage[i+dr[d]*k][j+dc[d]*k] == 'o'))	break;
				if (k == 4)	return true;
			}
		}
		
		return false;
	}

	
	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());
			stage = new char[N][N];
			
			for (int i = 0; i < N; i++)
				stage[i] = br.readLine().toCharArray(); // 'o':돌이 있는 칸, '.':돌이 없는 칸
			
			boolean check = false;
			loop:for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					if (stage[i][j] == 'o' && checkO(i, j)) {
						check = true;
						break loop;
					}
				}
			}
			
			if (check) 	System.out.println("#" + t + " YES");
			else	System.out.println("#" + t + " NO");
		}
	}
}