题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
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 let length = await readline() length = Number(length) const obj = {} while(line = await readline()){ let tokens = line.split(' '); let index = parseInt(tokens[0]); let value = parseInt(tokens[1]); if (!obj[index]) { obj[index] = value } else { obj[index] += value } } Object.entries(obj).forEach(([key, value]) => { console.log(`${key} ${value}`) }) }()