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