合并表格记录

输入:
4
0 1
0 2
1 2
3 4
输出:
0 3
1 2
3 4

#include <iostream>
#include <map>

using namespace std;

int main() {
    int n;
    while(cin >> n) {
        map<int, int> map;
        for(int i = 0; i < n; i ++) {
            int index, value;
            cin >> index >> value;
            map[index] += value;
        }
        for(auto it : map) cout << it.first << " " << it.second <<endl;
    }
    return 0;
}

知识点解析:

  1. hash表类似的输入
  2. map
  3. auto和itertor迭代器