From 6e836cf86ee888e20f1b208c767163f07c0d0b49 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:46:04 +0900 Subject: [PATCH] =?UTF-8?q?[20250206]=20BOJ=20/=20=EC=8B=A4=EB=B2=841=20/?= =?UTF-8?q?=20=EC=98=A4=EB=AA=A9=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../06 BOJ S1 \354\230\244\353\252\251.md" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "suyeun84/202502/06 BOJ S1 \354\230\244\353\252\251.md" diff --git "a/suyeun84/202502/06 BOJ S1 \354\230\244\353\252\251.md" "b/suyeun84/202502/06 BOJ S1 \354\230\244\353\252\251.md" new file mode 100644 index 00000000..509b269f --- /dev/null +++ "b/suyeun84/202502/06 BOJ S1 \354\230\244\353\252\251.md" @@ -0,0 +1,66 @@ +```java +import java.util.*; +import java.io.*; + +class Solution +{ + static int[][] dir = new int[][] {{1,0},{0,1},{1,1},{-1,1}}; + static int[][] board = new int[19][19]; + static Point answer = new Point(-1,-1,-1); + + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + + for (int i = 0; i < 19; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 19; j++) { + board[i][j] = Integer.parseInt(st.nextToken()); + } + } + + for (int i = 0; i <19; i++) { + for (int j = 0; j < 19; j++) { + if (board[i][j] == 1 || board[i][j] == 2) { + check(i, j, board[i][j]); + } + } + } + if (answer.x == -1) System.out.println(0); + else { + System.out.println(answer.type); + System.out.println(answer.y + " " + answer.x); + } + } + + public static void check(int y, int x, int type) { + for (int[] d : dir) { + int cnt = 1; + int ny = y + d[0]; + int nx = x + d[1]; + + while (ny >= 0 && ny < 19 && nx >= 0 && nx < 19 && board[ny][nx] == type) { + cnt += 1; + ny += d[0]; + nx += d[1]; + } + if (cnt == 5) { + if (y-d[0] >= 0 && x-d[1] >= 0 && y-d[0] < 19 && board[y-d[0]][x-d[1]] == type) continue; + answer = new Point(y+1, x+1, type); + } + } + } + + static class Point { + int y; + int x; + int type; + public Point(int y, int x, int type) { + this.y = y; + this.x = x; + this.type = type; + } + } +} + +```