题解 | #坐标移动#
坐标移动
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 () { const actionMap = { A: (point, step) => (point[0] -= step), D: (point, step) => (point[0] += step), W: (point, step) => (point[1] += step), S: (point, step) => (point[1] -= step), }; while ((line = await readline())) { const p = [0, 0]; line .split(";") .filter((item) => /^[ADWS]\d{1,2}$/.test(item)) .map((item) => item.match(/([ADWS])(\d+)/).slice(1, 3)) .forEach((action) => actionMap[action[0]](p, +action[1])); console.log(p.join(",")); } })();