Skip to content

Commit 6e836cf

Browse files
authored
[20250206] BOJ / 실버1 / 오목 / 김수연
1 parent 7f88479 commit 6e836cf

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
class Solution
6+
{
7+
static int[][] dir = new int[][] {{1,0},{0,1},{1,1},{-1,1}};
8+
static int[][] board = new int[19][19];
9+
static Point answer = new Point(-1,-1,-1);
10+
11+
public static void main(String[] args) throws Exception{
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
StringTokenizer st;
14+
15+
for (int i = 0; i < 19; i++) {
16+
st = new StringTokenizer(br.readLine());
17+
for (int j = 0; j < 19; j++) {
18+
board[i][j] = Integer.parseInt(st.nextToken());
19+
}
20+
}
21+
22+
for (int i = 0; i <19; i++) {
23+
for (int j = 0; j < 19; j++) {
24+
if (board[i][j] == 1 || board[i][j] == 2) {
25+
check(i, j, board[i][j]);
26+
}
27+
}
28+
}
29+
if (answer.x == -1) System.out.println(0);
30+
else {
31+
System.out.println(answer.type);
32+
System.out.println(answer.y + " " + answer.x);
33+
}
34+
}
35+
36+
public static void check(int y, int x, int type) {
37+
for (int[] d : dir) {
38+
int cnt = 1;
39+
int ny = y + d[0];
40+
int nx = x + d[1];
41+
42+
while (ny >= 0 && ny < 19 && nx >= 0 && nx < 19 && board[ny][nx] == type) {
43+
cnt += 1;
44+
ny += d[0];
45+
nx += d[1];
46+
}
47+
if (cnt == 5) {
48+
if (y-d[0] >= 0 && x-d[1] >= 0 && y-d[0] < 19 && board[y-d[0]][x-d[1]] == type) continue;
49+
answer = new Point(y+1, x+1, type);
50+
}
51+
}
52+
}
53+
54+
static class Point {
55+
int y;
56+
int x;
57+
int type;
58+
public Point(int y, int x, int type) {
59+
this.y = y;
60+
this.x = x;
61+
this.type = type;
62+
}
63+
}
64+
}
65+
66+
```

0 commit comments

Comments
 (0)