题解 | #坐标移动#

坐标移动

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

route = input()

route_list = route.split(";")  #变成列表,["A10", "S20", ...]

loc = [0,0]

for i in route_list:
    if len(i) < 2 or len(i)>3:
        continue
    elif i[0] == "A" and i[1:].isdigit():
        loc[0] -= int(i[1:])
    elif i[0] == "D" and i[1:].isdigit():
        loc[0] += int(i[1:])
    elif i[0] == "W" and i[1:].isdigit():
        loc[1] += int(i[1:])
    elif i[0] == "S" and i[1:].isdigit():
        loc[1] -= int(i[1:])
    else:
        continue

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

全部评论

相关推荐

offer多多的六边形战士很无语:看了你的博客,感觉挺不错的,可以把你的访问量和粉丝数在简历里提一下,闪光点(仅个人意见)
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务