题解 | #合并表记录#
提取不重复的整数
http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
map<int,int>mp;
while(n--)
{
int first,second;
cin>>first>>second;
if(mp.count(first))
{
int v=mp[first]+second;
mp[first]=v;
}
else
{
mp[first]=second;
}
}
//sort(mp.begin(),mp.end());
map<int,int>::iterator iter;
iter=mp.begin();
while(iter!=mp.end())
{
cout<<iter->first<<" "<<iter->second<<endl;
iter++;
}
}
return 0;
}