What I Learned/Algorithm Practice
[백준 - python] 1018번: 체스판 다시 칠하기
Interrobang
2022. 11. 30. 10:17
문제 링크
1018번: 체스판 다시 칠하기
첫째 줄에 N과 M이 주어진다. N과 M은 8보다 크거나 같고, 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 보드의 각 행의 상태가 주어진다. B는 검은색이며, W는 흰색이다.
www.acmicpc.net
문제 풀이
N, M = map(int, input().split())
start = []
cnt = []
for _ in range(N):
start.append(input())
for a in range(N - 7):
for b in range(M - 7):
index1 = 0
index2 = 0
for i in range(a, a + 8):
for j in range(b, b + 8):
if (i + j) % 2 == 0:
if start[i][j] != 'W':
index1 += 1
if start[i][j] != 'B':
index2 += 1
else:
if start[i][j] != 'B':
index1 += 1
if start[i][j] != 'W':
index2 += 1
cnt.append(min(index1, index2))
print(min(cnt))
*key point: 반복문과 조건문을 적절히 사용하여 모든 칸에 대해 검사해준다.