题解 | #合并表记录# CPP
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <iostream> #include <map> using namespace std; int main() { map<int, int> map_num; int n; cin >> n; int index, value; for (int i = 0; i < n; ++i) { cin >> index >> value; if (!map_num.count(index)) { map_num[index] = value; } else { map_num[index] += value; } } for (auto entry : map_num) { cout << entry.first << " "; cout << entry.second << endl; } return 0; }