牛客网 JavaScript Node ACM 模式

--------------------------------------个人笔记--------------------------------------

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

const arr = [];
rl.on('line', function (line) {    // 一行一行地输入
  arr.push(line);
  if (arr.length === 2) {
    rl.close();
  }
});

rl.on('close', function() {
  const matches = arr[0].match(new RegExp(arr[1], "ig"));
  const len = matches === null ? 0 : matches.length;
  console.log(len);    //输出
});

posted @ 2022-01-20 00:45  黄燃  阅读(1505)  评论(2编辑  收藏  举报