题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
# A10;S20;W10;D30;X;A1A;B10A11;;A10; # A=左,D=右,W=向上,S=下 s = input().split(';') start = [0,0] for i in s: if not 2 <= len(i) <= 3: #合法坐标为A(或者D或者W或者S) + 数字(两位以内) continue try: direction = i[0] step = int(i[1:]) if direction in ['A','D','W','S']: if 0 <= step <= 99: if direction == 'A': start[0] -= step elif direction == 'D': start[0] += step elif direction == 'W': start[1] += step elif direction == 'S': start[1] -= step except: continue print(str(start[0]) + ',' + str(start[1]))