python-for-coding-test
python-for-coding-test copied to clipboard
p.118번 게임 개발 문제
풀어봤는데 제가 풀어본 문제에 대해서는 모두 답이 맞는것 같은데 맞는 코드인지 아닌지 봐주실수 있나요? 혹시 봐주시기 힘드시면 맞는지 틀린지 검사할 수 있는 문제-답 세트를 알려주세요 ㅠㅠ
`
N, M = map(int, input().split())
A, B, d = map(int, input().split())
maps = []
for _ in range(N) :
maps.append(list(map(int, input().split())))
moves = [(-1, 0), (0, 1), (1, 0), (0, -1)]
turn = 0
result = 1
maps[A][B] = 2
while True :
# 왼쪽으로 방향 전환
if d == 0 :
d = 3
else :
d -= 1
turn += 1
#네 방향 모두 갈 수 없을 때
if turn == 5 :
nextA -= moves[d][0]
nextB -= moves[d][1]
# 인덱스 범위가 벗어나는지
if nextA >= 0 and nextB >= 0 and nextA < N and nextB < M :
# 바다가 아니면 뒤로 이동 바다면 종료
if maps[nextA][nextB] != 1 :
A, B = nextA, nextB
turn = 0
# 뒤가 바다니까 종료
else :
break
# 인덱스 범위가 벗어나는 곳이면 못가는 곳이라고 판단, 방향전환
else :
continue
#돌아보고 이동할지 말지
else :
nextA = A + moves[d][0]
nextB = B + moves[d][1]
if maps[nextA][nextB] == 0 :
A, B = nextA, nextB
maps[nextA][nextB] = 2
result += 1
turn = 0
#이동 못하면 처음으로 돌아가서 다시 방향전환
else :
continue
print(result)
`