题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
**javaScript V8 **
const a = readline();
const arrs = a.split(";");
const reg = /^(A|S|W|D)\d{1,2}$/g;
let x = 0;
let y = 0;
arrs.forEach((e) => {
if (reg.test(e)) {
let go = e.slice(1);
let fangx = e.slice(0, 1);
switch (fangx) {
case "A":
x -= parseInt(go);
break;
case "S":
y -= parseInt(go);
break;
case "W":
y += parseInt(go);
break;
case "D":
x += parseInt(go);
break;
}
reg.lastIndex=0
}
});
console.log(x + "," + y);