- 注意字典迭代的方式,常用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;
}
京公网安备 11010502036488号