//目录

Map的嵌套,HDU(1263)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263

新学的map的嵌套

#include <stdio.h>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int order;
        scanf("%d",&order);

        map<string,map<string,int> > maps;

        string name,place;
        int num;

        while(order--)
        {
            cin>>name>>place>>num;
            maps[place][name]+=num;
        }

        map<string,map<string,int>,> ::iterator pos;

        for(pos=maps.begin();pos!=maps.end();pos++)
        {
            cout<<pos->first<<endl;
            map<string,int> ::iterator pos2;

            for(pos2=pos->second.begin();pos2!=pos->second.end();pos2++)
            {
                cout<<"   |----"<<pos2->first<<"("<<pos2->second<<")"<<endl;
            }

        }
        if(t)
            cout<<endl;
    }
    return 0;
}

 

posted @ 2016-07-25 21:38  小草的大树梦  阅读(231)  评论(0编辑  收藏  举报