Softeer - 진정한 효도 (Python)

조민수·2024년 2월 2일

Softeer

목록 보기
7/20

Lv2, ⭐⭐


문제 풀이

단순 구현문제
주어진대로 수행하면 빠르게 해결할 수 있다.

from sys import stdin

# row 하나 확인 or col 하나 확인

board = []
for i in range(3):
    board.append(list(map(int, stdin.readline().split())))


def func(a, b, c):
    value = a + b + c - min(a, b, c) - max(a, b, c)
    return abs(value - a) + abs(value - b) + abs(value - c)

res = int(1e9)

# row 먼저

for i in range(3):
    a, b, c = board[i]
    if a == b == c:
        print(0)
        exit()
    else:
        tmp = func(a, b, c)
        res = min(res, tmp)

for i in range(3):
    arr = []
    for j in range(3):
        arr.append(board[j][i])
    if arr[0] == arr[1] == arr[2]:
        print(0)
        exit()
    else:
        tmp = func(arr[0], arr[1], arr[2])
        res = min(res, tmp)

print(res)
profile
Being a Modern Project Manager

0개의 댓글