#合并表记录#__huawei-no.8-1
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <iostream> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; int main(){ int n; cin >> n; vector<int> arr; unordered_map<int,int>map1; while(n-- >0){ int key,val; cin >> key >> val; if(map1.count(key) == 0){ map1[key] = val; arr.push_back(key); } else { map1[key] += val; } } sort(arr.begin(),arr.end()); for(int & i : arr){ cout << i <<" "<< map1[i] <<endl; } } // 64 位输出请用 printf("%lld")
非常好的题目,增进我对哈希表的理解,主要是这个count函数的使用,真的不错。