题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <iostream> using namespace std; #include<map> int main() { map<int,int> maps; int n=4,a,b; cin>>n; while(n>0) { cin>>a>>b; if(maps[a]==NULL)maps[a]=b; else if(maps[a]!=NULL)maps[a]+=b; n--; } //上网抄来的函数 for(auto &t:maps) { cout<<t.first<<' '<<t.second<<'\n'; } }