백준
[백준] 13567번: 로봇
초코바나나쉐이크
2024. 11. 19. 02:17
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]}')