题解 | #坐标移动#

坐标移动

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

import re

reg = "[ADWS]{1}[0-9]{1,2}"
direct_dict = {"A": [0, -1], "D": [0, 1], "W": [1, 1], "S": [1, -1]}
a = input().split(";")
validated = []
for t in a:
    match_cur = re.match(reg, t)
    if match_cur != None and match_cur.group() == t:
       
        validated.append(t)
cur_pos=[0,0]
for t in validated:
    index=direct_dict[t[0]][0]
    val= direct_dict[t[0]][1]

    cur_pos[index]= cur_pos[index]+ int(t[1:3])*val
print(cur_pos[0],end=',')
print(cur_pos[1])
全部评论

相关推荐

请问极越怎么样,刚拿offer能去吗
想好叫啥名字没:抓紧去,再不去就没机会了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务