题解 | #合并表记录#

合并表记录

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';
    }
}

全部评论

相关推荐

09-30 11:52
门头沟学院 Java
点赞 评论 收藏
分享
09-04 16:04
东北大学 Java
牛牛我呀想要offe...:筛选未通过有可能是测评挂了
投递京东等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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