[python ] 상하좌우

루송·2022년 10월 26일
0

python

목록 보기
6/7
post-thumbnail

상하좌우
p.110 예제 4-1
설명 생략

코드

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

dx = [0,0,-1,1]
dy = [-1,1,0,0]
move_types = ['L','R','U','D']

for plan in plans:
  for i in range(len(move_types)):
    if plan == move_types[i]:
      nx = x + dx[i]
      ny = y + dy[i]
  if nx < 1 or ny < 1 or nx > n or ny > n:
    continue
  x, y = nx, ny
print(x,y)

출력화면
업로드중..

0개의 댓글

관련 채용 정보