C++简洁代码:
#include<bits/stdc++.h> using namespace std; int main() { int n; while(cin >> n) { map<int, int> map; for(int i = 0; i < n; i ++) { int a, b; cin >> a >> b; map[a] += b; } for(auto it : map) cout << it.first << " " << it.second <<endl; } return 0; }