题解 | #坐标移动#

坐标移动

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

简单模拟

cor = (0,0)
directions = {'A':(-1,0),'S':(0,-1),'W':(0,1),'D':(1,0)}
for op in input().split(';'):
    if 1 < len(op) < 4 and op[0] in directions:
        if len(op) == 2 and op[1] in "0123456789":
            v = int(op[1])
        elif op[1] in "0123456789" and op[2] in "0123456789":
            v = int(op[1:3])
        else:
            continue
        dx, dy = directions[op[0]]
        cor = (cor[0]+dx*v, cor[1]+dy*v)
print(f'{cor[0]},{cor[1]}')
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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