HDU_1263_水果
思路:用STL中双重映射map。注意迭代器的写法!
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
while(n--)
{
int m;
scanf("%d", &m);
map<string, map<string, int> > fruit;
string type, place;
int num;
for(int i = 0; i < m; ++i)
{
cin >> type >> place >> num;
fruit[place][type] += num;
}
for(map<string, map<string, int> >::iterator it = fruit.begin(); it != fruit.end(); ++it)
{
cout << it->first << endl;
for(map<string, int>::iterator itt = it->second.begin(); itt != it->second.end(); ++itt)
{
cout << " |----" << itt->first << "(" << itt->second << ")" << endl;
}
}
if(n)
cout << endl;
}
return 0;
}