hys3835   3년 전

도와주십시오 ㅠㅠㅠ 어떤 문제가 있는지 아무리 고민해봐도 잘 모르겠습니다. 

global w, b
w = 0
b = 0
def check(list, size):
    c = 0
    for i in range(size):
        a = 0
        for j in range(size):
            a += list[i][j]
        if a == size:
            c += 1
        if a != 0 and a != size:
            return False
        elif a == 0 and c != 0:
            return False
    if c == 0:
        return 'w'
    else:
        return 'b'
def quad(list1, size):
    global w, b
    s = int(size / 2)
    if check(list1, size) == 'w':
        w += 1
    elif check(list1, size) == 'b':
        b += 1
    else:
        paper1 = []
        paper2 = []
        paper3 = []
        paper4 = []
        for i in range(0, s):
            paper1.append(list1[i][:s])
            paper2.append(list1[i][s:])
            paper3.append(list1[s+i][:s])
            paper4.append(list1[s + i][s:])
        quad(paper1, s)
        quad(paper2, s)
        quad(paper3, s)
        quad(paper4, s)
size = int(input())
paper = []
for i in range(size):
    list1 = list(map(int, input().split()))
    paper.append(list1)
quad(paper, size)
print(w)
print(b)

eytns   2년 전

check 함수의 6~15번 줄에서 보드를 줄별로 체크하는 것과 보드 전체를 체크하는 것 사이에서 오류가 발생합니다.

그리고 check 함수 안에서 리스트 변수 이름으로 'list'를 사용하는 것이 좀 껄끄럽습니다.

댓글을 작성하려면 로그인해야 합니다.