题解 | #合并表记录#

合并表记录

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

#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main() {
    int n;
    int a,b;
    map<int,int> h;
    while(cin>>n)
    {
        while(n--)
        {
            cin>>a>>b;
            if(h.find(a)==h.end())
               h.insert(make_pair(a,b));
            else h[a]+=b;
        }
        for(auto it=h.begin();it!=h.end();it++)
        {
            cout<<(*it).first<<" "<<(*it).second<<endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

认真搞学习:这么良心的老板真少见
点赞 评论 收藏
分享
猫头夜鹰:图书管理系统能有面试就怪了,放十年前都不行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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