diff --git a/kokeunho/.DS_Store b/kokeunho/.DS_Store index f6ac2a3..090da24 100644 Binary files a/kokeunho/.DS_Store and b/kokeunho/.DS_Store differ diff --git a/kokeunho/README.md b/kokeunho/README.md index ff3283d..3cec4b3 100644 --- a/kokeunho/README.md +++ b/kokeunho/README.md @@ -28,4 +28,5 @@ | 24차시 | 2025.04.30 | 분할 정복 | [행렬 제곱] | [#98](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/98) | | 25차시 | 2025.05.11 | 그리디 알고리즘 | [팔](https://www.acmicpc.net/problem/1105) | [#100](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/100) | | 26차시 | 2025.05.19 | 분할 정복 | [별 찍기 - 10](https://www.acmicpc.net/problem/2447) | [#102](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/102) | +| 28차시 | 2025.07.01 | 구현 | [스도쿠](https://www.acmicpc.net/problem/2580) |[#116](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/116) | --- diff --git "a/kokeunho/\352\265\254\355\230\204/28-kokeunho.java" "b/kokeunho/\352\265\254\355\230\204/28-kokeunho.java" new file mode 100644 index 0000000..437170e --- /dev/null +++ "b/kokeunho/\352\265\254\355\230\204/28-kokeunho.java" @@ -0,0 +1,64 @@ +import java.util.*; + +public class Main { + static int[][] map; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + map = new int[9][9]; + List blank = new ArrayList<>(); + for (int i = 0; i < 9; i++) { + for (int j = 0; j < 9; j++) { + map[i][j] = sc.nextInt(); + if (map[i][j] == 0) { + blank.add(new int[]{i, j}); + } + } + } + sudoku(blank, 0); + } + public static void sudoku(List blank, int count) { + if (count == blank.size()) { + for (int i = 0; i < 9; i++) { + for (int j = 0; j < 9; j++) { + System.out.print(map[i][j] + " "); + } + System.out.println(); + } + System.exit(0); + } + + int[] coor = blank.get(count); + List candiNum = checkCandi(coor[0], coor[1]); + + for (int num : candiNum) { + map[coor[0]][coor[1]] = num; + sudoku(blank, count+1); + map[coor[0]][coor[1]] = 0; + } + } + /*map[row][col]에 들어갈 수 있는 숫자 모음*/ + public static List checkCandi(int row, int col) { + boolean[] used = new boolean[10]; + + for (int i = 0; i < 9; i++) { + used[map[row][i]] = true; + used[map[i][col]] = true; + } + + int startRow = (row / 3) * 3; + int startCol = (col / 3) * 3; + for (int i = startRow; i < startRow + 3; i++) { + for (int j = startCol; j < startCol + 3; j++) { + used[map[i][j]] = true; + } + } + List candiNum = new ArrayList<>(); + + for (int i = 1; i <= 9; i++) { + if (!used[i]) candiNum.add(i); + } + return candiNum; + } +}