슈콩

[SWEA] 오목 판정 본문

Algorithms/SWEA

[SWEA] 오목 판정

shukong 2025. 11. 9. 16:01

 

[문제]

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

 

SW Expert Academy

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

swexpertacademy.com

 

 

 

[소스 코드]

import java.util.*;
import java.io.*;
public class Solution {
	static int n;
	static char[][] map;
	static int[] dr = {1,1,1,0};
	static int[] dc = {-1,0,1,1};
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			n = Integer.parseInt(br.readLine());
			map = new char[n][n];
			for(int i=0;i<n;i++) {
				String s = br.readLine();
				for(int j=0;j<n;j++) {
					map[i][j] = s.charAt(j);
				}
			}
			boolean possible = false;
			for(int i=0;i<n;i++) {
				for(int j=0;j<n;j++) {
					if(map[i][j]!='o') continue;
					for(int d=0;d<4;d++) {
						if(find(i,j,d)) possible = true;
					}
				}
			}
			if(possible) System.out.println("#"+tc+" YES");
			else System.out.println("#"+tc+" NO");
		}
	}
	private static boolean find(int i,int j,int d) {
		char c = map[i][j];
		int nr = i;
		int nc = j;
		for(int v=1;v<5;v++) {
			nr += dr[d];
			nc += dc[d];
			if(nr<0 || nr>=n || nc<0 || nc>=n) return false;
			if(map[nr][nc]!=c) return false;
		}
		return true;
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 0/1 Knapsack  (0) 2025.11.10
[SWEA] 단순 2진 암호코드  (0) 2025.11.09
[SWEA] 7일차 - 암호생성기  (0) 2025.11.09
[SWEA] 재미있는 오셀로 게임  (3) 2025.11.07
[SWEA] 진기의 최고급 붕어빵  (0) 2025.11.06