#include <iostream> #include <map> using namespace std; int main() { int n; cin >> n; map<int, int> my_map; map<int, int>::iterator it; for(int i = 0; i < n; i++){ int a, b; cin >> a >> b; if(my_map.find(a) != my_map.end()) my_map[a] += b; else my_map[a] = b; } for(it = my_map.begin(); it != my_map.end(); it++){ cout << it->first << ' ' << it->second << endl; } return 0; } // 64 位输出请用 printf("%lld")
map<int, int>::iterator it;
my_map.find(a)
my_map.end()
my_map.begin()