题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
# 初始输入 n = input().strip().split(';') m = ['A','D','S','W']. # 对输入进行处理 a = [_ for _ in n if len(_) > 1] b = [] c = {} x,y = 0,0 # 判断有效坐标 for i in a : if i[0] in m and i[1:].isnumeric() : b.append(i) # 对有效坐标保存成字典格式 for i in b : c[i[0]] = c.get(i[0],0) + eval(i[1:]) # 遍历 字典进行判断 for i,j in c.items(): if i == 'A': x -= j elif i == 'D': x += j elif i == 'W': y += j elif i == 'S': y -= j print(f'{x},{y}')