题解 | #HJ17 坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
Python+正则表达式
import re
s = input()
mvs = [mv for mv in s.split(';') if re.match(r"^([AWSD]\d{1,2})?$", mv)]
x, y = 0, 0
for mv in mvs:
if mv:
if mv[0] == 'A':
x -= int(mv[1:])
elif mv[0] == 'S':
y -= int(mv[1:])
elif mv[0] == 'W':
y += int(mv[1:])
elif mv[0] == 'D':
x += int(mv[1:])
print(f"{x},{y}")
C语言版本
待更新