题解 | #坐标移动#

坐标移动

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]}")

全部评论

相关推荐

重生我想学测开:嵌入式的问题,我准备入行京东外卖了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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