标签:map
1 5 apple shandong 3 pineapple guangdong 1 sugarcane guangdong 1 pineapple guangdong 3 pineapple guangdong 1
guangdong |----pineapple(5) |----sugarcane(1) shandong |----apple(3)这题可以用map的二维来做,学习了。和二维数组差不多。#include<stdio.h> #include<string.h> #include<iostream> #include<string> #include<map> #include<algorithm> using namespace std; char s1[100],s2[100]; int main() { int T,n,m,i,j,a; string b; scanf("%d",&T); while(T--) { map<string,int> mp; map<string,int>::iterator it; map<string,map<string,int> > hash; map<string,map<string,int> >::iterator p; mp.clear(); hash.clear(); scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%s%s%d",s1,s2,&a); hash[s2][s1]+=a; } for(p=hash.begin();p!=hash.end();p++){ cout<<p->first<<endl; mp=p->second; for(it=mp.begin();it!=mp.end();it++){ cout<<" "<<"|----"<<it->first<<"("<<it->second<<")"<<endl; } } if(T!=0)cout<<endl; } return 0; }
标签:map
原文地址:http://blog.csdn.net/kirito_acmer/article/details/45575157