题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201?tpId=37&tags=&title=&difficulty=0&judgeStatus=0&rp=1&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37
let readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let num = 0; let obj = {}; rl.on('line', line => { if(num === 0) { num = parseInt(line); } else { let [k, v] = line.split(' '); if (k in obj) { obj[k] += Number(v); } else { obj[k] = Number(v); } } }) rl.on('close', () => { Object.keys(obj).map((it) => { console.log(it, obj[it]); }) })