题解 | #合并表记录#

合并表记录

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

  1. 注意字典迭代的方式,常用auto会节省大量时间。
#include<bits/stdc++.h>

using namespace std;

int main(){

    int T,key,val;
    cin>>T;

    map<int,int> res;

    while(T--){
        cin>>key>>val;

        if(!res.count(key)){

            res[key] = val;
        }else{

            res[key] += val;
        }
    }

    //output

    for(auto it = res.begin(); it!= res.end(); it++){
        cout<<it->first<<" "<<it->second<<endl;
    }



    return 0;
}
大厂笔试题题解 文章被收录于专栏

主要是公司笔试题得一些总结

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
但听说转正率很低,我现在有在实习了,好纠结要不要去
熬夜脱发码农:转正率低归低,但是实习的经历你可以拿着,又不是说秋招不准备了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务