题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include<iostream> #include<map> #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { map<int, int>maps; int n; cin >> n; map<int, int>::iterator it; for (int i = 1; i <= n; ++i) { int k, v; cin >> k >> v; maps[k] += v; //maps[k] += v; } for (auto c : maps) cout << c.first << " " << c.second << endl; /*for (it=maps.begin();it!=maps.end();it++) { cout << it->first << " " << it->second << endl; }*/ return 0; }