题解 | #合并表记录#

合并表记录

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

index 用一个vector存起来。要审题。按升序排序。
#include<iostream>;
#include<bits/stdc++.h>;
using namespace std;
int main(){
    int n, index, value;
    vector<int>***bsp;   cin>> n;
    unordered_map<int, int>map;
    for(int i= 0; i< n; i++){
        cin>>index;
        cin>>value;
        if(map.count(index) == 0){
            map[index] = value;
            p.push_back(index);
        }
        else{
            map[index] = map[index] + value;
        }
    }
    sort(p.begin(), p.end());
    for(int j = 0; j< p.size(); j++){
        cout<<p[j]<<' '<<map[p[j]]<<endl;
    }
}


全部评论

相关推荐

不愿透露姓名的神秘牛友
03-30 21:35
爱蜜莉雅碳劝退测开:裁员裁大动脉了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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