백준 1652 누울 자리를 찾아라

김민영·2023년 1월 26일
0

알고리즘

목록 보기
100/125

과정

  • 단순 구현
  • 세로와 가로에서 . 이 연속으로 있는 구간을 찾기
  • 세로, 가로에 대해 2중 반복문을 돌리면서, . 이 2개 이상 붙어있으면 cnt를 추가하는 방식으로 했다.
N = int(input())

map_lst = [list(input()) for _ in range(N)]


garo_cnt = 0
sero_cnt = 0

for i in range(N):
    cnt = 0
    for j in range(N):
        if map_lst[i][j] == "X":
            cnt = 0
        elif map_lst[i][j] == ".":
            cnt += 1
            if cnt == 2:
                garo_cnt += 1

    cnt = 0
    for j in range(N):
        if map_lst[j][i] == "X":
            cnt = 0
        elif map_lst[j][i] == ".":
            cnt += 1
            if cnt == 2:
                sero_cnt += 1

print(garo_cnt, sero_cnt)
  • 반복되는 코드를 함수로 만들면 좋을 것 같다고 생각.
profile
노션에 1차 정리합니당 - https://cream-efraasia-f3c.notion.site/4fb02c0dc82e48358e67c61b7ce8ab36?v=

0개의 댓글