题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import sys
import re
pos = [0,0]
for line in sys.stdin:
a = line.split(';')
for item in a:
#print('item=',item)
if re.match(r'(\d+)$',item[1:]):
#print('item=',item[0],':',[item[1:]])
if item[0] == 'A':
pos[0] -= int(item[1:])
elif item[0] == 'D':
pos[0] += int(item[1:])
elif item[0] == 'S':
pos[1] -= int(item[1:])
elif item[0] == 'W':
pos[1] += int(item[1:])
print(pos[0],pos[1],sep=',')
查看8道真题和解析