题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
def judge(val: str) -> bool:
if len(val) != 0 and val[0] in ["A", "S", "W", "D"]:
try:
step = int(val[1:])
if 0 <= step <= 99: # 移动步长限制在两位以内
return True
except Exception as e:
return False
else:
return False
seq = input().split(";")
origin = [0, 0]
for sub in seq:
if judge(sub):
if sub.startswith("A"):
step = int(sub[1:])
origin[0] -= step
elif sub.startswith("D"):
step = int(sub[1:])
origin[0] += step
elif sub.startswith("W"):
step = int(sub[1:])
origin[1] += step
else:
step = int(sub[1:])
origin[1] -= step
print(f"{origin[0]},{origin[1]}")
深信服公司福利 885人发布
