http://acm.hdu.edu.cn/showproblem.php?pid=1263

STL中map的练习

View Code
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
    int n,m,k,i;
    int f=0;
    scanf("%d",&n);
    while(n--)
    {
        if(!f)f++;
        else putchar('\n');
        map <string ,map<string,int> > M;
        string location,type;
        scanf("%d",&m);
        while(m--)
        {
            cin >> type >> location >> k;
            M[location][type]+=k;
        }
        map <string ,map<string,int> > :: iterator it1;
        for(it1=M.begin();it1!=M.end();it1++)
        {
            cout << it1->first << endl;
            map <string,int> :: iterator it2;
            for(it2=it1->second.begin();it2!=it1->second.end();it2++)
                cout << "   |----" << it2->first << "(" << it2->second << ")" << endl;
        }
    }
    return 0;
}