题解 | #合并表记录# JavaScript node
合并表记录
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 num = parseInt(await readline()); //第一个数,表示要输入的键值对个数 let obj = {}; for (let i = 0; i < num; i++) { let str = await readline(); let [k, v] = str.split(" "); if (obj[k]) { //如果存在就加 obj[k] = obj[k] + parseInt(v); } else { //如果不存在就赋值 obj[k] = parseInt(v); } } //console.log(obj) //这里打印发现js对象会自动按照键的值排序 for (let j in obj) { console.log(j + " " + obj[j]); } })();