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)
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<algorithm> #include<cstdlib> #include<set> #include<queue> #include<stack> #include<vector> #include<map> #define N 100010 #define Mod 10000007 #define lson l,mid,idx<<1 #define rson mid+1,r,idx<<1|1 #define lc idx<<1 #define rc idx<<1|1 typedef long long ll; const int INF = 1000010; using namespace std; int main() { int t; while ( cin >> t ) { while ( t-- ) { int n; scanf ( "%d", &n ); string a, b; int v; map<string, map<string, int> >mp; for ( int i = 0; i < n; i++ ) { cin >> a >> b >> v; mp[b][a] += v; } map<string, map<string, int> >::iterator it; for ( it = mp.begin(); it != mp.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 ( t ) cout << endl; } } return 0; }
原文地址:http://blog.csdn.net/acm_baihuzi/article/details/41520333