Algorithm/COS
[COS Pro 1급, Python] 2차 6번 : 로봇을 움직여주세요
JMcunst
2022. 2. 25. 10:21
728x90
반응형
문제 유형
코딩
난이도
easy
Note
Nothing
Code
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
# 2차 6번
def solution(commands):
answer = []
x = 0
y = 0
list_commands = list(commands)
for i in list_commands:
if i == 'L':
x -= 1
elif i == 'R':
x += 1
elif i == 'U':
y += 1
else:
y -= 1
answer.append(x)
answer.append(y)
return answer
commands = "URDDL"
ret = solution(commands)
print("solution 함수의 반환 값은", ret, "입니다.")
※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.
728x90
반응형