[백준] 10709번 기상캐스터

거북이·2023년 1월 8일
0

백준[실버5]

목록 보기
74/114
post-thumbnail

💡문제접근

현재 지점으로부터 동쪽에 구름이 존재한다면 구름이 존재한다는 뜻을 나타내는 변수인 is_cloud에 bool값을 넣어 참거짓을 가려주고 지금부터 몇 분뒤 처음으로 하늘에 구름이 오는지를 구하기 위해 구름이 있던 지점의 값을 is_cloud_location에 저장하여 각 지점의 w값에서 빼줘 구하고자 하는 값을 저장했다. 로직을 짜는데 조금 시간이 소요됐던 문제였다.

💡코드(메모리 : 30616KB, 시간 : 48ms)

H, W = map(int, input().split())
weather = []
for _ in range(H):
    weather.append(list(input()))

for h in range(H):
    is_cloud = False
    for w in range(W):
        if weather[h][w] == "c":
            weather[h][w] = 0
            is_cloud = True
            is_cloud_location = w
        elif weather[h][w] == ".":
            if is_cloud == True:
                weather[h][w] = w - is_cloud_location
            else:
                weather[h][w] = -1

for h in range(H):
    for w in range(W):
        print(weather[h][w], end=" ")
    print()

💡소요시간 : 8m

0개의 댓글