学习STL,之后发现map容器非常适合这个题目,因为容器本身就具有排序功能
#include<iostream>
#include<map>
using namespace std;
int main()
{
int num;
int number, value;
map<int, int>table;
cin >> num;
while (cin>>number>>value)
{
table[number] += value;
}
for (auto i = table.cbegin(); i != table.cend();++i)
{
cout << i->first << " " << i->second << endl;
}
system("pause");
return 0;
}