题解 | #坐标移动#

坐标移动

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

actions = input().split(";")
x, y = 0, 0
for action in actions:
    if len(action) < 2 or len(action) > 3:
        continue
    try:
        num = int(action[1:])
    except Exception:
        continue
    if action[0] == 'A':
        x -= num
    elif action[0] == 'D':
        x += num
    elif action[0] == 'S':
        y -= num
    elif action[0] == 'W':
        y += num       
print("{},{}".format(x, y))

全部评论

相关推荐

对空六翼:你真幸运,碰见这么好的人,不像我,秋招的时候被室友骗进cx了
实习好累,可以辞职全力准...
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务