题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
python3解法
def func():
x = 0
y = 0
lst1 = ['A','D','W','S']
lst2 = [i for i in range(1,100)]#建立一个1~99的列表
lst3 = input().split(';')
for i in lst3:
if 2<=len(i)<=3:#值得长度需要在2和3之间,例如A不满足A150不满足,必须是A1或者A15才满足长度需求
try:#加try是为了避免下面int(i[1:])报错,当i = A1A的时候,int(i[1:])会报错
val = int(i[1:])
itm = i[0]
if itm in lst1:
if val in lst2:
if itm == 'A':
x -= val
elif itm == 'D':
x += val
elif itm == 'W':
y += val
else :
y -= val
except:
continue
print(f'{x},{y}')
func()