题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import sys import re def do(str): x = 0 y = 0 # 获取坐标 # 循环 l_str = str.split(';') for item in l_str: # 处理正常坐标 # 剔除异常坐标 tem = item.strip() if re.match('^[A|W|S|D]\d{1,2}$', tem): if 'A' in tem: x -= int(tem[1:]) elif 'D' in tem: x += int(tem[1:]) elif 'W' in tem: y += int(tem[1:]) elif 'S' in tem: y -= int(tem[1:]) return x,y if __name__ == '__main__': str = sys.stdin.readline().strip() r = do(str) print("{},{}".format(r[0], r[1]))