본문 바로가기
Algorithm/Programmers

[구현] 상하좌우 (파이썬)

by 그랴 2022. 8. 4.

 

n = int(input())
a = input().split()
x, y = 1, 1

#공간을 벗어나는 움직임은 무시
i = 0
while i < len(a):
  if a[i] == 'L':
    #왼쪽으로 한 칸 이동
    if y != 1: y -= 1
  elif a[i] == 'R':
    #오른쪽으로 한 칸 이동
    if y != n: y += 1
  elif a[i] == 'U':
    #위로 한 칸 이동
    if x != 1: x -= 1
  elif a[i] == 'D':
    #아래로 한 칸 이동
    if x != n: x += 1
  print(a[i],x, y)

  i += 1
  if i == len(a): break

print(x, y)