본문 바로가기

Algorithm/SWEA

[SWEA / python] 1974. 스도쿠 검증

import sys
sys.stdin = open("input.txt", "r")

T = int(input())

for test_case in range(1, T + 1):
    num_list = []
    result = 1

    for i in range(9):
        tmp = list(map(int,input().split()))
        num_list.append(tmp)

    #1 가로, 세로로 겹치는 숫자 있나 확인
    for i in range(9):
        check_r = [0 for i in range(10)]
        check_c = [0 for i in range(10)]
        check_r[0] = 1
        check_c[0] = 1

        for k in range(9):
            check_r[num_list[i][k]] += 1
            check_c[num_list[k][i]] += 1

        if (max(check_r)!= 1 and min(check_r)!=1):
            result = 0
            break

        if (max(check_c)!= 1 and min(check_c)!=1):
            result = 0
            break

    #3*3에서 겹치는 숫자 있나 확인
    for i in range(3):
        for j in range(3):
            check = [0 for i in range(10)]
            check[0] = 1

            for k in range(3):
                for l in range(3):
                    check[num_list[3*i+k][3*j+l]] += 1

            if (max(check) != 1 and min(check) != 1):
                result = 0
                break

    print("#"+str(test_case)+" "+str(result))