-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_2615.java
More file actions
92 lines (66 loc) · 1.82 KB
/
BOJ_2615.java
File metadata and controls
92 lines (66 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class Main {
public static int[][] map = new int[19][19];
public static int[][] movepos = {
{1,0},{1,1},{0,1},{-1,1}
};
public static boolean isIn(int y, int x) {
if (x < 0 || x >= 19)return false;
if (y < 0 || y >= 19)return false;
return true;
}
public static void input() throws Exception{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 19; i++) {
String[] line = in.readLine().split(" ");
for (int j = 0; j < 19; j++) {
map[i][j] = line[j].charAt(0) - '0';
}
}
}
public static void main(String[] args) throws Exception {
input();
// search
// Left First - top First
for (int j = 0; j < 19; j++) {
for (int i = 0; i < 19; i++) {
if (map[i][j] == 0)continue;
int nowColor = map[i][j];
for (int k = 0; k < 4; k++) {
int seriesCount = 1;
int dely = movepos[k][0];
int delx = movepos[k][1];
int goy = dely + i;
int gox = delx + j;
while(true) {
if(!isIn(goy,gox))break;
if(map[goy][gox] != nowColor)break;
seriesCount++;
goy += dely;
gox += delx;
}
//반대 방향 탐색
dely *= -1;
delx *= -1;
goy = dely + i;
gox = delx + j;
while(true) {
if(!isIn(goy,gox))break;
if(map[goy][gox] != nowColor)break;
seriesCount++;
goy += dely;
gox += delx;
}
if(seriesCount == 5) {
System.out.println(nowColor);
System.out.println((i+1) + " " + (j+1));
return ;
}
}
}
}
System.out.println("0");
}
}