题解 | #合并表记录#

合并表记录

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;
}
大厂笔试题题解 文章被收录于专栏

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

全部评论

相关推荐

一天代码十万三:实习东西太少了,而且体现不出你业务,3个月不可能就这点产出吧,建议实习多写点,玩具项目面试官都不感兴趣的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务