题解 | #坐标移动#

坐标移动

https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29

moves = input().split(";")
x, y = 0, 0

def move(direction, steps):
    global x, y
    if direction == "A":
        x -= steps
    elif direction == "D":
        x += steps
    elif direction == "W":
        y += steps
    elif direction == "S":
        y -= steps

for move_str in moves:
    if len(move_str) > 1 and move_str[1:].isdigit():
        move(move_str[0],int(move_str[1:]))

print(f'{x},{y}')

全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务