题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
try: while True: inpt = input().split(';') startpoint = [0, 0] # print(inpt) for i in range(len(inpt)): # 把不符合输入要求的都设置成空字符串 if len(inpt[i]) != 3 and len(inpt[i]) != 2: # 长度不是2,且不是3的肯定不合法 inpt[i] = '' if len(inpt[i]) == 3 and (not inpt[i][1].isdigit() or not inpt[i][2].isdigit()): inpt[i] = '' # 长度为3但距离不是数字的 if len(inpt[i]) == 2 and not inpt[i][1].isdigit(): inpt[i] = '' # 长度为2但距离不是数字的 # print(inpt) for i in inpt: # 遍历指令 if i != '': fangxiang = i[0] # 提取方向 distence = int(i[1:]) # 提取距离 # print(fangxiang,distence) if fangxiang == 'A': startpoint[0] -= distence elif fangxiang == 'D': startpoint[0] += distence elif fangxiang == 'W': startpoint[1] += distence elif fangxiang == 'S': startpoint[1] -= distence print(f'{startpoint[0]},{startpoint[1]}') except EOFError: pass