문제: 무단 배포 금지로 인해 사이트 주소로 남깁니다.
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14ABYKADACFAYh
정답 코드:
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])
'SWEA' 카테고리의 다른 글
1227. [S/W 문제해결 기본] 7일차 - 미로2(DFS, BFS) (0) | 2024.07.17 |
---|---|
1215. [S/W 문제해결 기본] 3일차 - 회문1 (0) | 2024.07.16 |
5215. 햄버거 다이어트 (0) | 2024.07.15 |
2007. 패턴 마디의 길이 (0) | 2024.07.15 |
1284. 수도 요금 경쟁 (0) | 2024.07.15 |