题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import re str = input().split(";") pattern = r"([A,S,D,W])(\d+)(?![a-zA-Z])" x = 0 y = 0 for s in str: match = re.match(pattern, s) if match: if match.group(1) == "A": x = x - int(match.group(2)) elif match.group(1) == "D": x = x + int(match.group(2)) elif match.group(1) == "W": y = y + int(match.group(2)) elif match.group(1) == "S": y = y - int(match.group(2)) print("{},{}".format(x, y))