SWEA_1974) 스도쿠 검증
SWEA
# D2
1974) 스도쿠 검증 (19.10.04)
문제 링크 (SW Expert Academy)
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
|
import java.io.*;
import java.util.*;
public class Solution {
public static int[][] map;
public static int ii(int i) {
boolean[] ch = new boolean[10];
for(int k=0;k<9;k++) {
int a = map[i][k];
if(ch[a]) return 0;
ch[a] = true;
}
return 1;
}
public static int jj(int j) {
boolean[] ch = new boolean[10];
for(int k=0;k<9;k++) {
int a = map[k][j];
if(ch[a]) return 0;
ch[a] = true;
}
return 1;
}
public static int sq(int k, int r) {
boolean[] ch = new boolean[10];
for(int i=k;i<k+3;i++) {
for(int j=r;j<r+3;j++) {
int a = map[i][j];
if(ch[a]) return 0;
ch[a] = true;
}
}
return 1;
}
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer tk;
int t = Integer.parseInt(br.readLine());
for(int i=1;i<=t;i++) {
int ans = 1;
map = new int[9][9];
for(int p=0;p<9;p++) {
tk = new StringTokenizer(br.readLine());
for(int q=0;q<9;q++) {
map[p][q] = Integer.parseInt(tk.nextToken());
}
}
for(int k=0;k<9;k++) {
if(ii(k)==0) {
ans = 0;
break;
}
}
if(ans!=0){
for(int k=0;k<9;k++) {
if(jj(k)==0) {
ans = 0;
break;
}
}
}
if(ans!=0){
outfor:
for(int k=0;k<9;k=k+3) {
for(int r=0;r<9;r=r+3) {
if(sq(k, r)==0) {
ans = 0;
break outfor;
}
}
}
}
bw.write("#" + i + " " + ans + "\n");
}
bw.flush();
bw.close();
}
}
| cs |
댓글
댓글 쓰기