题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
input_list = input().split(';')
initial = [0,0]
for item in input_list:
if not 2 <= len(item) <= 3:#排除一些非法的语句,如A100
continue
try:#用try except避开如A1A这样的非法语句
direction = item[0]
step = int(item[1:])
if direction in ['A', 'D', 'W', 'S']:
if 0 <= step <= 99:#这里可以避开A1A
if direction == 'A':
initial[0] -= step
elif direction == 'D':
initial[0] += step
elif direction == 'S':
initial[1] -= step
elif direction == 'W':
initial[1] += step
except:
continue
print(str(initial[0]) + ',' + str(initial[1]))摘抄,学习了
MDPI公司福利 443人发布