付翔的专栏
在鄙视中成长 记录成长的点滴
posts - 106,  comments - 32,  trackbacks - 0
map 中嵌套map 使用

#include
<iostream>
#include
<map>
#include
<string>
using namespace std;
int main()
{
    
string ss,ss1;
    
int k,n,m,t=1;
    cin
>>n;
    
while (n--)
    {
        map
< string,map<string,int> >mm;// 可以嵌套map
        if (t>1) cout<<endl;
        cin
>>k;
        
while (k--)
        {
            cin
>>ss1>>ss>>m;
            mm[ss][ss1]
+=m;
        }
        
// map内部是默认排序的
        map< string,map<string,int> >::iterator itr;
        map
< string,int > ::iterator itr1;
        
for (itr=mm.begin();itr!=mm.end();itr++)
        {
            cout
<<(*itr).first<<endl;
            
for (itr1=(*itr).second.begin();itr1!=(*itr).second.end();itr1++)
                cout
<<"   |----"<<(*itr1).first<<'('<<(*itr1).second<<')'<<endl;
        }
        t
++;
    }
    
return 0;
}

posted on 2010-06-26 17:08 付翔 阅读(291) 评论(0)  编辑 收藏 引用 所属分类: c++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2010年6月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

CSDN - 我的blog地址

博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜