HJ8.合并表记录
#include <iostream>
#include <map>
int main() {
int num = 0;
int key = 0, val = 0;
std::map<int, int> dict;
std::cin >> num;
for (int i = 0; i < num; ++i) {
std::cin >> key >> val;
dict[key] += val;
}
for (auto& i : dict) {
std::cout << i.first << ' ' << i.second << '\n';
}
return 0;
}
解题思路
难点1:map就可以了