SWEA
1210. [S/W 문제해결 기본] 2일차 - Ladder1
zhelddustmq
2024. 7. 16. 15:36
문제: 무단 배포 금지로 인해 사이트 주소로 남깁니다.
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14ABYKADACFAYh
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
정답 코드:
dx = [1,-1]
for test_case in range(10):
T = int(input())
arr = [list(map(int, input().split())) for _ in range(100)]
dest = []
for j in range(100):
if arr[99][j] == 2:
dest.append(99)
dest.append(j)
break
current_index = dest
while current_index[0] > 0:
flag = False
for i in range(2):
# 배열 크기를 벗어나지 않을때만 좌우 조사
if -1 < current_index[1] + dx[i] < 100:
# 좌우로 움직여야 할 때
if arr[current_index[0]][current_index[1] + dx[i]] == 1:
# 움직여야 할 곳으로 한 칸 옮기고
current_index[1] += dx[i]
flag = True
#위에 갈 길이 나올 때까지 옆으로 움직임
while arr[current_index[0] - 1][current_index[1]] == 0:
current_index[1] += dx[i]
if flag:
break
current_index[0] -= 1
print(f"#{T}", current_index[1])