정답 풀이
# 실버5
n = int(input())
condo = [list(input()) for _ in range(n)]
cnt = 0
rows = 0
cols = 0
for i in range(n):
for j in range(n):
if condo[i][j] == '.':
cnt += 1
else:
if cnt >= 2:
rows += 1
cnt = 0
else:
cnt = 0
if cnt >= 2:
rows += 1
cnt = 0
else:
cnt = 0
# 세로
cnt = 0
for i in range(n):
for j in range(n):
if condo[j][i] == '.':
cnt += 1
else:
if cnt >= 2:
cols += 1
cnt = 0
else:
cnt = 0
if cnt >= 2:
cols += 1
cnt = 0
else:
cnt = 0
print(rows, cols)
rows = 0
cols = 0
for i in range(n):
for j in range(n-1):
if condo[i][j] == '.':
if condo[i][j] == condo[i][j+1] and (j+1 == n-1 or condo[i][j+2] == 'X'):
rows += 1
else:
if condo[i][j+1] == condo[i][j + 2] and (j + 2 == n - 1 or condo[i][j + 3] == 'X'):
rows += 1
for j in range(n-1):
for i in range(n):
if condo[i][j] == '.':
if condo[j][i] == condo[j+1][i] and (j+1 == n-1 or condo[j+2][i] == 'X'):
cols += 1
else:
if condo[j+1][i] == condo[j+2][i] and (j+2 == n-1 or condo[j+3][i] == 'X'):
cols += 1
print(rows, cols)
'알고리즘 문제풀이' 카테고리의 다른 글
백준 25496 장신구 명장 임스 Python 그리디 정렬 실버5 (0) | 2024.03.14 |
---|---|
백준 8979 올림픽 Python 구현 정렬 실버5 (0) | 2024.03.13 |
백준 1978 소수찾기 Python 수학 소수 브론즈2 (1) | 2024.03.12 |
백준 11651 좌표 정렬하기 2 Python 정렬 실버5 (0) | 2024.03.11 |
백준 5585. 거스름돈 Python 그리디 브론즈2 (0) | 2024.03.11 |