题解 | #合并表记录#

合并表记录

http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201

while(num=readline()){
    let numArr=[]
    let obj={}
    for(let i=0;i<num;i++){
//         numArr.push(readline())
         let strs=readline().split(' ');
        if(obj[strs[0]]){
            obj[strs[0]]=obj[strs[0]]+Number(strs[1])
        }else{
            obj[strs[0]]=Number(strs[1])
        }
    }
    for(let key in obj){
        console.log(`${key} ${obj[key]}`)
    }
}

全部评论

相关推荐

01-07 15:50
四川大学 Java
看日出看日落:好好背八股,做算法。我身边跟你bg差不多的基本都大厂暑期
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务