题解 | 坐标移动

坐标移动

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

com = input().split(';')
cor = dict()
for s in com:
    if len(s) < 2:
        continue
    if s[0].isalpha():
        ori = s[0]
        if s[1:].isdigit():
            dis = int(s[1:])
            try:
                cor[ori] += dis
            except:
                cor[ori] = dis

coor = [0, 0]
for key, value in cor.items():
    if key == 'A':
        coor[0] -= value
    elif key == 'D':
        coor[0] += value
    elif key == 'W':
        coor[1] += value
    elif key == 'S':
        coor[1] -= value

print(f"{coor[0]},{coor[1]}")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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