题解 | 合并表记录
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <bits/stdc++.h> #include <map> using namespace std; int main(){ map<int, int> cur; int n; cin >> n; while (n--) { int l,r; cin >> l >> r; cur[l] += r; } for (auto it : cur) cout << it.first << ' ' << it.second << endl; return 0; }
注意利用map特性,可以直接创建