题解 | #合并表记录#

合并表记录

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

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

int main() {
    int num;
    cin>>num;
    map<int,int> m;
    for(int i=0;i<num;i++)
    {
        int index,value;
        cin>>index>>value;
        auto it=m.find(index);
        if(it!=m.end())
        {
            it->second+=value;
        }
        else{
            m.insert(pair<int, int>(index,value));
        }
    }
    for(auto i:m)
    {
        cout<<i.first<<" "<<i.second<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

故事和酒66:假设一下,就算报了培训班,不还是要投简历,只是项目改了。那不如先写几个培训班的项目,纯靠编,然后试试有没有面试。如果真有再报也不迟,如果没有还是没有,那就不是培训班的问题了。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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