p. 110
s=int(input())
plans=input().split()
dire=['R','L','U','D']
dx=[0,0,-1,1]
dy=[1,-1,0,0]
nx=1
ny=1
x=1
y=1
for plan in plans:
for i in range(len(dire)):
if dire[i]==plan:
nx=x+dx[i]
ny=y+dy[i]
if nx<1 or ny<1 or nx>s or ny>s:
continue
else:
x=nx
y=ny
print(x,y)
댓글