题解 | #坐标移动#

坐标移动

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

from operator import concat
import re
list = list(map(str,input().split(';')))
init = [0,0]

for str in list:
    if re.fullmatch('[ASWD]+[0-9]+',str) is not None:##fullmatch 正则匹配 没有匹配上返回None 
        tag = str[0]
        num = int(str[1:])

        if tag=="A":
            init[0]-=num
        elif tag=="S":
            init[1]-=num
        elif tag=="W":
            init[1]+=num
        elif tag=="D":
            init[0]+=num

print('{},{}'.format(init[0],init[1]))

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务