题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
def judge(val: str) -> bool:
if len(val) != 0 and val[0] in ["A", "S", "W", "D"] and val[1:].isdigit():
step = int(val[1:])
if 0 <= step <= 99:
return True
else:
return False
seq = input().strip().split(";")
x, y = 0, 0
for sub in seq:
if judge(sub):
if sub.startswith("A"):
step = int(sub[1:])
x -= step
elif sub.startswith("D"):
step = int(sub[1:])
x += step
elif sub.startswith("W"):
step = int(sub[1:])
y += step
else:
step = int(sub[1:])
y -= step
print(f"{x},{y}")
查看2道真题和解析