题解 | #坐标移动#

坐标移动

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(","));
  }
})();

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-30 11:34
真的很糟糕:黑奴听了都流泪啊
点赞 评论 收藏
分享
07-07 12:25
门头沟学院 Java
程序员牛肉:你这个智邮公司做的就是那个乐山市税务系统的服务吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务