题解 | #合并表记录#

合并表记录

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

#include <iostream>
using namespace std;
#include<map>

int main() {
    map<int,int> maps;
    int n=4,a,b;
    cin>>n;
    while(n>0)
    {
        cin>>a>>b;
        if(maps[a]==NULL)maps[a]=b;
        else if(maps[a]!=NULL)maps[a]+=b;
        n--;
    }

    //上网抄来的函数
    for(auto &t:maps)
    {
        cout<<t.first<<' '<<t.second<<'\n';
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务