hdu-1263-水果(二维map)

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

stl的map是用一颗二叉排序树储存元素的,排序准则取决于key的元素类型,string的默认准则就是字母顺序。用迭代器遍历map时,按照排序树的顺序访问元素,所以输出是字母顺序

code:

#include
#include
#include
using namespace std;
int main()
{
    int T;
    cin>>T;
    while(T--){
        map > m;
        string a , b ;
        int n,num;
        cin>>n;
        while(n--){
            cin>>a>>b>>num;
            m[b][a]+=num;
        }
        map >::iterator it_1;
        map::iterator it_2;
        for(it_1=m.begin();it_1!=m.end();it_1++){
            cout<first<second.begin();it_2!=it_1->second.end();it_2++){
                cout << "   |----" << it_2->first << "(" << it_2->second << ")" <

你可能感兴趣的:(acm_stl)