然而map底层是红黑树好像
#include <iostream> #include <map> using namespace std; int main() { int n; while(cin>>n) { map<int,int>m; pair<int,int>temp; for(int i = 0;i < n;++i) { cin>>temp.first>>temp.second; if(m.find(temp.first)!=m.end()) { m[temp.first]+=temp.second; } else m[temp.first]=temp.second; } for(auto x:m) { cout<<x.first<<' '<<x.second<<endl; } } }