题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
s = input().split(';') s = ' '.join(s).split() # removing the empty strings x, y = 0, 0 for i in s: if 1 < len(i) < 4: dir = i[0] dis = i[1:] if dis.isdigit(): if dir == 'A': x -= int(dis) elif dir == 'D': x += int(dis) elif dir == 'W': y += int(dis) elif dir == 'S': y -= int(dis) print(f'{x},{y}')
不符合条件的都无操作,所以只要把有操作的情况列出来就行