题解 | #坐标移动# Python3:模拟

坐标移动

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

if __name__ == '__main__':
    steps = list(input().strip().split(';'))
    x, y = 0, 0
    for step in steps:
        if len(step) < 1: continue
        direction = step[0]
        dist = step[1:]
        if not dist.isnumeric(): continue
        dist = int(dist)
        if direction == 'A':
            x = x - dist
        elif direction == 'D':
            x = x + dist
        elif direction == 'W':
            y = y + dist
        elif direction == 'S':
            y = y - dist
    print(','.join(map(str, [x, y])))

#23届找工作求助阵地##软件开发薪资爆料##我的实习求职记录##你们的毕业论文什么进度了#
算法之路 文章被收录于专栏

有关数据结构、算法等的文章

全部评论

相关推荐

迷茫的大四🐶:摊牌了,我是25届的,你们也不招我
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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