题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <iostream>
#include <map>
#include <unordered_map>
using namespace std;
int main() {
map<int, int>umap;
int n;
cin >> n;
int key, value;
while (n--) {
cin >> key >> value;
umap[key] += value;
}
for (auto& it : umap) {
cout << it.first << " " << it.second << endl;
}
}
数据量应该是改了,不能直接用数组做hashtable
查看14道真题和解析