华为OJ】【008-合并表记录】
题目链接:
https://blog.csdn.net/DERRANTCM/article/details/51315163
C++实现:
void main()
{
int n1,n2,n3,n4;
cin >> n1;
n2=n1;
map<int, int> nMap;
while(n2--)
{
cin >> n3 >> n4;
if (nMap.find(n3) == nMap.end())
nMap[n3] = n4;
else
nMap[n3] = nMap[n3] + n4;
}
for (map<int, int>::iterator it = nMap.begin(); it != nMap.end();it++)
cout << it->first <<" " << it->second << endl;
system("pause");
}