题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include<iostream>
#include<map>
using namespace std;
int main() {
int n, index, value;
map<int, int>m;
pair<int, int> p;
cin >> n;
while (n--) {
cin >> p.first >> p.second;
if (m.find(p.first) != m.end()) {
m[p.first] += p.second;
} else {
m.insert(p);
}
}
for (auto i : m) {
cout << i.first << " " << i.second << endl;
}
}
