백준 6873번: Returning Home #Python

ColorlessDia·2024년 10월 20일

algorithm/baekjoon

목록 보기
336/807
import sys

route_history = []

while True:
    line = sys.stdin.readline().rstrip()

    if line == 'SCHOOL':
        break

    route_history.append(line)

direction = ''

for i, history in enumerate(route_history[::-1], 1):

    if history == 'L':
        direction = 'RIGHT'
        continue
    
    if history == 'R':
        direction = 'LEFT'
        continue

    print(f'Turn {direction} onto {history} street.')

    history = ''

print(f'Turn {direction} into your HOME.')

0개의 댓글