题解 | #坐标移动#

坐标移动

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

import re
recmd = r"\w\d+$"
heng = 0
zong = 0

listcmdsplit = input().split(';')

for cmd in listcmdsplit:
    if len(cmd) <= 3 and re.match(recmd, cmd):
        if "A" in cmd:
            heng = heng - int(cmd[1:])
        if "D" in cmd:
            heng = heng + int(cmd[1:])
        if "W" in cmd:
            zong = zong + int(cmd[1:])
        if "S" in cmd:
            zong = zong - int(cmd[1:])

print(f"{heng},{zong}")

全部评论

相关推荐

把球:这个听过,你加了就会发现是字节的hr
点赞 评论 收藏
分享
尊尼获获:闺蜜在哪?
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务