蛮好的题目,练STL,双重Map
#include<iostream> #include<map> #include<string> using namespace std; int main() { int a; cin>>a; while(a--) { map<string,map<string,int> >m; int b,count; cin>>b; string x,y; while(b--) { cin>>x>>y>>count; m[y][x]+=count; } map<string,map<string,int> > ::iterator it; for(it=m.begin();it!=m.end();it++) { cout<<it->first<<endl; map<string,int>::iterator it2; for(it2=it->second.begin();it2!=it->second.end();it2++) cout<<" |----"<<it2->first<<"("<<it2->second<<")"<<endl; } if(a) cout<<endl; } return 0; }