题解 | #合并表记录#

合并表记录

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}`)
    })
}()

全部评论

相关推荐

10-11 17:45
门头沟学院 Java
走吗:别怕 我以前也是这么认为 虽然一面就挂 但是颇有收获!
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务