题解 | #合并表记录#
合并表记录
http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
- 注意字典迭代的方式,常用auto会节省大量时间。
#include<bits/stdc++.h>
using namespace std;
int main(){
int T,key,val;
cin>>T;
map<int,int> res;
while(T--){
cin>>key>>val;
if(!res.count(key)){
res[key] = val;
}else{
res[key] += val;
}
}
//output
for(auto it = res.begin(); it!= res.end(); it++){
cout<<it->first<<" "<<it->second<<endl;
}
return 0;
}大厂笔试题题解 文章被收录于专栏
主要是公司笔试题得一些总结
查看17道真题和解析