题解 | #合并表记录#
合并表记录
http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> imap;
int index, value;
for (int i = 0; i < n; ++i) {
cin >> index >> value;
imap[index] += value; // 不需要判断是否存在,利用map[index]初始化为0的性质
}
for (auto &p : imap) {
cout << p.first << " " << p.second << endl;
}
}