题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
my_str = input().split(';')
start =[0,0]
for item in my_str:
if not 2 <= len(item) <= 3:
continue #
try:
direction = item[0]
step = int(item[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]))
查看14道真题和解析
