题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
orderList = list(input().split(';'))
def legalOrder(astr):
moveList = 'ADWS'
if len(astr) < 2:
return False
elif astr[0] not in moveList:
return False
elif not astr[1:].isdigit():
return False
else:
return True
o = orderList.copy() # 进行遍历删除操作时,一定要把list复制新的一份再遍历!
for order in o:
legalFlag = legalOrder(order)
if not legalFlag:
orderList.remove(order)
start = [0, 0]
for order in orderList:
if order.startswith('A'):
start[0] = start[0] - int(order[1:])
elif order.startswith('S'):
start[1] = start[1] - int(order[1:])
elif order.startswith('W'):
start[1] = start[1] + int(order[1:])
elif order.startswith('D'):
start[0] = start[0] + int(order[1:])
else:
pass
print(','.join(map(str, start)))