题解 | #坐标移动#

坐标移动

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

list1 = [0, 0]
list2 = ["A", "D", "S", "W"]
list3 = input().split(";")

for st in list3:
    num = len(st)
    if 2 <= num <= 3:
        if st[0] in list2:
            try:
                t = int(st[1:])
            except:
                continue
            if st[0] == "A":
                list1[0] -= t
            elif st[0] == "D":
                list1[0] += t
            elif st[0] == "W":
                list1[1] += t
            else:
                list1[1] -= t
    else:
        continue

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

全部评论

相关推荐

点赞 评论 收藏
转发
投递网易雷火等公司7个岗位
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务