题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
// Write your code here
while ((line = await readline())) {
let dictions = line.split(";");
let x = 0; // 横向
let y = 0; // 纵向
let isDiction = /^[A|D|W|S][0-9]{1,2}$/;// 用来检测格式是否正确
dictions.forEach((item) => {
let i = 0;
if (isDiction.test(item)) {
let d = item.slice(0, 1);
let count = parseInt(item.slice(1));
switch (d) {
case "A":
x -= count;
break;
case "D":
x += count;
break;
case "W":
y += count;
break;
case "S":
y -= count;
break;
default:
break;
}
}
});
console.log(`${x},${y}`);
}
})();
