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");
}
}
}
'Algorithm > 백준+프로그래머스+SWEA+정올+구름' 카테고리의 다른 글
[Algorithm] 백준 8958 OX퀴즈 (0) | 2021.08.22 |
---|---|
[Algorithm] 백준 1914 하노이 탑 (0) | 2021.08.21 |
[Algorithm] 백준 1223 계산기2 (0) | 2021.08.20 |
[Algorithm] 백준 2839 설탕 배달 (0) | 2021.08.20 |
[Algorithm] SWEA 1247 최적경로 (0) | 2021.08.20 |