题解 | 合并表记录

合并表记录

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

#include <iostream>
#include <map>
#include <unordered_map>

using namespace std;

int main() {
    map<int, int> mp;
    int n;
    cin>>n;
    while(n--)
    {
        int x, y;
        cin>>x>>y;
        mp[x]+=y;
    }
    for(auto it:mp)
    cout<<it.first<<" "<<it.second<<"\n";
}

哈希思路没得说,注意到样例也是按键值升序输出的,所以用map不用unordered_map

#牛客春招刷题训练营#

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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