题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import re
x = 0
y = 0
move = input().split(";")
for i in move:
if ((len(i) == 3) and re.match(r"[A-Z]\d\d",i)) \
or (len(i) == 2 and re.match(r"[A-Z]\d",i)): #使用正则匹配判断
direction = i[0]
distance = int(i[1:]) #取出方向和移动距离
if direction == 'A':
x = x - distance
elif direction == 'W':
y = y + distance
elif direction == 'S':
y =y - distance
elif direction == 'D':
x = x + distance
print(f"{x},{y}")