题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263
思路:可以直接结构体快排,也可以用map(强大的STL)
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <iterator>
#include <ctype.h>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
while(n--)
{
map <string, map<string, int> > a;
map <string, int> b;
map<string, map<string, int> >:: iterator i;
map<string, int>:: iterator j;
int m;
scanf("%d", &m);
string name, palce;
int num;
while(m--)
{
cin >> name >> palce >> num;
a[palce][name] += num;
}
for(i = a.begin(); i != a.end(); i++)
{
cout << i -> first << endl;
b = i -> second;
for(j = b.begin(); j != b.end(); j++)
{
cout << " |----" << j -> first << "(" << j -> second << ")" << endl;
}
}
if(n)
cout << endl;
}
return 0;
}