-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD2_1974_스도쿠검증.java
92 lines (81 loc) · 2.79 KB
/
D2_1974_스도쿠검증.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.swea.D2;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class D2_1974_스도쿠검증 {
static boolean flag;
static int[][] sdk;
static int[] check;
public static void main(String[] args) throws IOException {
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new FileReader("C:\\intelliJ_workspaces\\Algorithm\\src\\com\\swea\\D2\\testcase\\1974input.txt"));
int T = Integer.parseInt(br.readLine());
int N = 9;
for (int t = 1; t <= T; ++t) {
sdk = new int[N][N];
check = new int[N + 1];
flag = true;
// 스도쿠 채우기
for (int i = 0; i < N; ++i) {
String[] s = br.readLine().split(" ");
for (int j = 0; j < N; ++j) {
sdk[i][j] = Integer.parseInt(s[j]);
}
}
// for (int i = 0; i < N; ++i) {
// System.out.println(Arrays.toString(sdk[i]));
// }
// 가로
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
check[sdk[i][j]]++;
if (check[sdk[i][j]] > 1) {
flag = false;
break;
}
}
for (int c = 0; c < check.length; ++c) check[c] = 0;
if (!flag) break;
}
// 세로
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
check[sdk[j][i]]++;
if (check[sdk[j][i]] > 1) {
flag = false;
break;
}
}
for (int c = 0; c < check.length; ++c) check[c] = 0;
if (!flag) break;
}
// 구역
checkSdk(0, 0);
if (flag) System.out.println("#" + t + " 1");
else System.out.println("#" + t + " 0");
}
}
private static void checkSdk(int i, int j) {
if (i > 8 || j > 8) return;
else {
for (int c = i; c < 3 + i; ++c) {
for (int r = j; r < 3 + j; ++r) {
check[sdk[c][r]]++;
if (check[sdk[c][r]] > 1) {
flag = false;
break;
}
}
}
for (int k = 0; k < check.length; ++k) check[k] = 0;
if (!flag) return;
else if (flag) {
checkSdk(i + 3, j);
checkSdk(i, j + 3);
checkSdk(i + 3, j + 3);
}
}
}
}