-
Notifications
You must be signed in to change notification settings - Fork 0
/
lotto.py
60 lines (45 loc) · 1.37 KB
/
lotto.py
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
# 이곳에 소스코드를 작성하세요.
# Python3 만 지원됩니다.
def check_row(a, x, y):
for number in a[x]:
if a[x].count(number) > 1 and number == a[x][y]:
return False
return True
def check_col(a, x, y):
col = [a[j][y] for j in range(9)]
for number in col:
if col.count(number) > 1 and number == a[x][y]:
return False
return True
def check_square(a, x, y):
check = [False] * 10
seq = (x // 3) * 3 + (y // 3)
for i in range(3):
r = i + (seq // 3) * 3
for j in range(3):
c = j + (seq % 3) * 3
if check[a[r][c]] and a[r][c] == a[x][y]:
return False
check[a[r][c]] = True
return True
def find_answer(x, y):
b = a
for i in range(1, 10):
b[x][y] = i
if check_row(b, x, y) and check_col(b, x, y):
return i
num_of_test = int(input())
for test in range(1, num_of_test + 1):
answer = []
k = int(input())
a = [list(map(int, input().split())) for _ in range(9)]
for x in range(9):
for y in range(9):
if not check_row(a, x, y) and not check_col(a, x, y):
answer.append(x + 1)
answer.append(y + 1)
answer.append(find_answer(x, y))
print("#%d" %test, end=" ")
for x in answer:
print(x, end=" ")
print()