python + 正则表达式
re.match 一行判断操作指令是否合法
order = input().split(';') start = [0,0] import re for i in order: if re.match("^[ASWD][1-9]?[0-9]$", i): if i[0] == 'A': start[0] -= int(i[1:]) if i[0] == 'S': start[1] -= int(i[1:]) if i[0] == 'W': start[1] += int(i[1:]) if i[0] == 'D': start[0] += int(i[1:]) print(str(start[0])+','+str(start[1]))