题解 | #坐标移动#

坐标移动

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

dir = input().strip(" ").split(";")   # 分割输入,去除空格
cor = [0, 0]

for item in dir:
    if not 2<= len(item) <=3:
        continue                      # 判断长度是否合法
    try:
        step = int(item[1:])          # 提取步长
        if 0 < step <= 99:            # 判断步长是否合法
            if item[0] == "A":        # 判断方向是否合法,并且进行移动
                cor[0] -= step
            elif item[0] == "D":
                cor[0] += step
            elif item[0] == "S":
                cor[1] -= step
            elif item[0] == "W":
                cor[1] += step
    except:
        continue

print("{},{}".format(cor[0], cor[1]))

#23届找工作求助阵地##我的实习求职记录#
全部评论

相关推荐

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