题解 | #坐标移动#

坐标移动

https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29?tpId=37&tqId=21240&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fdifficulty%3D3%26page%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=3&judgeStatus=undefined&tags=&title=

import sys

init = [0, 0]
for line in sys.stdin:
    a = line.split(";")
    for index in range(0, len(a)):
        site = a[index]
        # print(site)
        if len(site) == 0:
            continue
        if len(site) > 3:
            continue
        if site[0] not in ["A", "D", "W", "S"]:
            continue
        if not site[1:].isdigit():
            continue

        if site[0] == "A":
            init[0] = init[0] - int(site[1:])
        elif site[0] == "D":
            init[0] = init[0] + int(site[1:])
        elif site[0] == "W":
            init[1] = init[1] + int(site[1:])
        elif site[0] == "S":
            init[1] = init[1] - int(site[1:])

print(",".join(list(map(str, init))))

全部评论

相关推荐

牛客618272644号:佬携程工作怎么样,强度大吗
点赞 评论 收藏
分享
11-13 20:32
门头沟学院 Java
面向未来编程code:我没看到他咋急,他不就问你个问题。。。
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务