Skip to content

Commit 39911d2

Browse files
committed
BOJ_2615 : 오목
1 parent 511de0c commit 39911d2

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

week2/BOJ_2615(오목).java

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int[][] omok = new int[21][21];
9+
for(int i=1; i<=19; i++) {
10+
StringTokenizer st = new StringTokenizer(br.readLine());
11+
for(int j=1; j<=19; j++) {
12+
omok[i][j] = Integer.parseInt(st.nextToken());
13+
}
14+
}
15+
for(int i=1; i<=19; i++) {
16+
for(int j=1; j<=19; j++) {
17+
int color = omok[i][j];
18+
if(color == 0) {
19+
continue;
20+
}
21+
int count1 = 0;
22+
int count2 = 0;
23+
for(int k=0; k<5; k++) {
24+
// 세로
25+
if(i+k <= 19) {
26+
if(omok[i][j] == omok[i+k][j]) {
27+
count1++;
28+
}
29+
}
30+
// 가로
31+
if(j+k <= 19) {
32+
if(omok[i][j] == omok[i][j+k]) {
33+
count2++;
34+
}
35+
}
36+
}
37+
if((count1 == 5 && omok[i+5][j] != color && omok[i-1][j] != color)
38+
|| (count2 == 5 && omok[i][j+5] != color && omok[i][j-1] != color)) {
39+
System.out.println(color);
40+
System.out.println(i + " " + j);
41+
return;
42+
}
43+
44+
count1 = 0;
45+
count2 = 0;
46+
for(int k=0; k<5; k++) {
47+
// 오른쪽 위 대각선
48+
if(j-k >= 1 && i+k <= 19) {
49+
if(omok[i][j] == omok[i+k][j-k]) {
50+
count1++;
51+
}
52+
}
53+
// 오른쪽 아래 대각선
54+
if(i+k <= 19 && j+k <= 19) {
55+
if(omok[i][j] == omok[i+k][j+k]) {
56+
count2++;
57+
}
58+
}
59+
}
60+
if(count1 == 5 && omok[i+5][j-5] != color && omok[i-1][j+1] != color) {
61+
System.out.println(color);
62+
System.out.println((i+4) + " " + (j-4));
63+
return;
64+
}
65+
66+
if(count2 == 5 && omok[i+5][j+5] != color && omok[i-1][j-1] != color) {
67+
System.out.println(color);
68+
System.out.println(i + " " + j);
69+
return;
70+
}
71+
}
72+
}
73+
System.out.println("0");
74+
}
75+
}

0 commit comments

Comments
 (0)