题解 | #坐标移动#
坐标移动
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])
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])