728x90
import java.util.Scanner;
public class Main {
static int[][] map = new int[21][21];
static int[][][] memo = new int[21][21][4];
static int[] dx = { 1, 1, 0, -1 };
static int[] dy = { 0, 1, 1, 1 };
static StringBuilder sb = new StringBuilder();
public static String countFive() {
for(int j = 1; j <= 19; j++) {
for(int i = 1; i <= 19; i++) {
if(map[i][j] != 0) {
for(int d = 0; d < 4; d++) {
if(memo[i][j][d] == 0 && calc(i,j,d,map[i][j]) == 5) {
return map[i][j] + "\n" + i + " " + j + "\n";
}
}
}
}
}
return "0"; //승부 결정되지 않았을때
}
public static int calc(int x, int y, int dir, int color) {
int nx = x + dx[dir];
int ny = y + dy[dir];
if(map[nx][ny] == color) {
return memo[nx][ny][dir] = calc(nx,ny,dir,color) + 1;
}
return 1;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
for(int i = 1; i <= 19; i++) {
for(int j = 1; j <= 19; j++) {
map[i][j] = scan.nextInt();
}
}
System.out.println(countFive());
scan.close();
}
}
728x90
'CS > Algorithm' 카테고리의 다른 글
[ JAVA / 백준 : 11650] 좌표정렬하기 (0) | 2021.08.06 |
---|---|
[ JAVA / 백준 : 1316 ] 그룹단어체커 (0) | 2021.08.02 |
[ JAVA / 백준 : 11723] 집합 (0) | 2021.07.30 |
[ JAVA / 백준 : 7568 ] 덩치 (0) | 2021.07.30 |
[ JAVA / 백준 : 2108 ] 통계학 (0) | 2021.07.30 |