https://www.acmicpc.net/problem/13567
m,n = map(int,input().split())
dir = [[1,0],[0,1],[-1,0],[0,-1]] #동,북,서,남
pos = [0,0]
count = 0
for i in range(n):
command, num = map(str, input().split())
if command == 'MOVE':
pos[0] += dir[count][0] * int(num)
pos[1] += dir[count][1] * int(num)
#좌표 넘어갈 시
if pos[0] < 0 or pos[0] > m or pos[1] < 0 or pos[1] > m:
print(-1)
exit()
#print(f'현재 위치:{pos[0]}, {pos[1]}')
elif command == 'TURN':
if int(num) == 0:
count+=1
elif int(num) == 1:
count-=1
if count < 0:
count+=4
elif count >3:
count-=4
print(f'{pos[0]} {pos[1]}')
'백준' 카테고리의 다른 글
[백준] 16506번: CPU(파이썬) (0) | 2024.11.22 |
---|---|
[백준] 3986번: 좋은 단어(파이썬) (1) | 2024.11.21 |
[백준] 14493번: 과일노리(파이썬) (0) | 2024.10.25 |
[백준] 28324번: 스케이트 연습(파이썬) (0) | 2024.10.21 |
[백준] 2622번: 삼각형만들기(파이썬) (0) | 2024.10.19 |