Python题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import sys
s = sys.stdin.readline().strip().split(';')
list1 = []
for i in s:
if len(i) == 3:
if (i[0] == 'A' or i[0] == 'D' or i[0] == 'W' or i[0] == 'S') and i[1].isdigit() and i[2].isdigit():
list1.append(i)
elif len(i) == 2:
if (i[0] == 'A' or i[0] == 'D' or i[0] == 'W' or i[0] == 'S') and i[1].isdigit():
list1.append(i)
x, y = 0, 0
for j in list1:
if j[0] == 'A':
x -= int(j[1:])
elif j[0] == 'D':
x += int(j[1:])
elif j[0] == 'W':
y += int(j[1:])
elif j[0] == 'S':
y -= int(j[1:])
print(f"{x},{y}")
