题解 | #合并表记录# 基于有序哈希表-map实现
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <iostream>
#include <map>
using namespace std;
int main() {
    int n;
    cin >> n;
    map<int,int> mp;
    for(int i=0; i<n; i++){
        int k,value;
        cin >> k;
        cin >> value;
        if(mp.find(k) == mp.end()){
            mp[k] = value;
        }else{
            mp[k] += value;
        }
    }
    for(const auto & num:mp){
        cout << num.first << ' ' << num.second << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")
查看12道真题和解析