diff --git "a/lkhyun/202502/05 BOJ \354\213\244\353\262\2041 \354\230\244\353\252\251.md" "b/lkhyun/202502/05 BOJ \354\213\244\353\262\2041 \354\230\244\353\252\251.md" new file mode 100644 index 00000000..3d331fc9 --- /dev/null +++ "b/lkhyun/202502/05 BOJ \354\213\244\353\262\2041 \354\230\244\353\252\251.md" @@ -0,0 +1,77 @@ +```java +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) throws FileNotFoundException { + Scanner sc = new Scanner(System.in); + int[][] grid = new int[19][19]; + for(int i=0;i<19;i++) { + for(int j=0;j<19;j++) { + grid[i][j] = sc.nextInt(); + } + } + + int[] di = {1,1,0,-1}; + int[] dj = {0,1,1,1}; + for(int i=0;i<19;i++) { + for(int j=0;j<19;j++) { + if(grid[i][j]==1 || grid[i][j]==2) { //흑돌 혹은 백돌이면 + int check = grid[i][j]; + int count = 1; + for(int k=0;k<4;k++) { //팔방탐색 + int newi = i+di[k]; + int newj = j+dj[k]; + if(newi>=0&&newi<19&&newj>=0&&newj<19) {//벗어나지 않으면 + if(grid[newi][newj]==check) {//이전 돌과 같으면 + count=2; + for(int l=0;l<4;l++) {//최대 육목까지 체크 + newi = newi+di[k]; + newj = newj+dj[k]; + if(newi>=0&&newi<19&&newj>=0&&newj<19) { + if(grid[newi][newj]==check){ + if(count==5){break;} + count++; + } + else{ + if(count==5){ + if(i-di[k]>=0&&i-di[k]<19&&j-dj[k]>=0&&j-dj[k]<19) + { + if(grid[i-di[k]][j-dj[k]] == check){ + break; + } + } + System.out.println(check); + System.out.println((i+1)+" "+(j+1)); + return; + } + break; + } + } + else { + if(count==5){ + if(i-di[k]>=0&&i-di[k]<19&&j-dj[k]>=0&&j-dj[k]<19) + { + if(grid[i-di[k]][j-dj[k]] == check){ + break; + } + } + System.out.println(check); + System.out.println((i+1)+" "+(j+1)); + return; + } + break; + } + } + } + } + } + } + } + } + System.out.println("0"); + } + +} +```