题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import sys action=input().split(';') # print(action,type(action),len(action)) direct=['W','A','S','D'] step=[[0,1],[-1,0],[0,-1],[1,0]] D=dict(zip(direct,step)) # print(D,type(D)) # print([i+j for i,j in zip([2,3],[0,1])])#生成对应列表相加 walk=[] point=[0,0] for x in action: if x=='': continue #被空元素恶心了 elif x[0] in direct and 2<=len(x)<=3: try: buchang=int(x[1:]) xremove=buchang*D[x[0]][0]#hengzou yremove=buchang*D[x[0]][1]#zongzou point[0]+=xremove point[1]+=yremove # print(point,type(point)) except: continue else: continue print(f'{point[0]},{point[1]}')