题解 | #合并表记录#
合并表记录
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;
}
}
