题解 | #记票统计#

记票统计

https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894

const readline = require('readline');

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

const lines: Array<string[]>[] = [];

rl.on('line', function (line) {
  lines.push(line.split(' '));
});

rl.on('close', () => {
  const totalVotes = Number(lines[2][0]);
  let validVotes = 0;
  lines[1].forEach((item) => {
    const votes = lines[3].filter((i) => i === item);
    validVotes += votes.length;
    console.log(`${item} : ${votes.length}`);
  });
  console.log(`Invalid : ${totalVotes - validVotes}`);
});

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务