题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import sys
import re
str=input().split(';')
x,y=0,0
pat=re.compile(r'^[ADWS]\d{1,2}$')
for i in str:
match=re.search(pat,i)
#print(match)
if match:
if match.string[0]=='A':
x-=eval(match.string[1:])
elif match.string[0]=='D':
x+=eval(match.string[1:])
elif match.string[0]=='W':
y+=eval(match.string[1:])
elif match.string[0]=='S':
y-=eval(match.string[1:])
print(x,end=',')
print(y)

查看18道真题和解析