题解:
采用顺序表。考虑到题目中没有规定指数上界,为避免RE,拟不采用数组。参考了http://blog.csdn.net/inlovecy/article/details/15208473后,最终采用map。
源码:
#include <iostream>
#include <map>
using namespace std; int main()
{
int n;
cin >> n;
while (n--) {
int exp = , t1, t2, c = ;
bool flg = false;
map<int, int>ep;
while (c--)
while (cin >> t1 >> t2) {
if (t2 < ) break;
if (ep.find(t2) != ep.end())ep[t2] += t1;
else ep.insert(make_pair(t2, t1));
}
for (map<int, int>::reverse_iterator it = ep.rbegin(); it != ep.rend(); it++) {
if (it->second == )continue;
cout << "[ " << it->second << " " << it->first << " ] ";
flg = true;
}
if(flg) cout << endl;
}
return ;
}