题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
# 2024年3月18日 下午15:09
# wujie
# A10;S20;W10;D30;X;A1A;B 10AA11;;A10;
s = input().split(';')
start = [0,0] # 注意起点一定是写在这里的
for i in s:# 一定是遍历字符列表本身,而不是位置
if not 2 <= len(i) <= 3: # 这个范围一定是这样的,否则不能提交//合法坐标为A(或者D或者W或者S) + 数字(两位以内)
continue
else:
try:
DD = i[0]
step = int(i[1:])
if DD in ['A','D','W','S']:
if 0 <= step <= 99:
if DD == 'A':
start[0] -= step
elif DD == 'D':
start[0] += step
elif DD == 'W':
start[1] += step
elif DD == 'S':
start[1] -= step
except:
continue # 这个用来处理'A1A'
print(str(start[0]) + ',' + str(start[1]))


查看9道真题和解析