题解 | #合并表记录#
合并表记录
http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
const readline = require('readline') var rl = readline.createInterface({ input:process.stdin, output:process.stdout }) var length = 0 var arr = [] rl.on('line',(line)=>{ if(length == 0){ length = parseInt(line) }else{ arr.push(line) } }) rl.on('close',()=>{ var res = [] arr.forEach((val,index)=>{ var item = val.split(' ') if(res[parseInt(item[0])]){ res[parseInt(item[0])] = parseInt(res[parseInt(item[0])]) + parseInt(item[1]) }else{ res[parseInt(item[0])] = item[1] } }) res.forEach((val,index)=>{ if(val){ console.log(index + ' ' + val) } }) })