Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1362 Accepted Submission(s): 532
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype>
#include <cstring>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
//Constant Declaration
/*--------------------------*/
//#define LL long long
#define LL __int64
const int M=1000000;
const int INF=1<<30;
const double EPS = 1e-11;
const double PI = acos(-1.0);
/*--------------------------*/
// some essential funtion
/*----------------------------------*/
void Swap(int &a,int &b){ int t=a;a=b;b=t; }
int Max(int a,int b){ return a>b?a:b; }
int Min(int a,int b){ return a<b?a:b; }
int Gcd(int a,int b){ while(b){b ^= a ^=b ^= a %= b;} return a; }
/*----------------------------------*/
//for (i = 0; i < n; i++)
/*----------------------------------*/
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t, case1 = 0;
scanf("%d", &t);
int n, m;
int i, j;
//scanf("%d%d", &n, &m);
while (t--)
{
if (case1 == 0)
{
case1++;
}
else
{
puts("");
}
string place, fruit;
map <string, map<string, int> > A;//注意中间还有个map,后面的>>中间加个空格,不然Compilation Error
scanf("%d" ,&n);
for (i = 0; i < n; i++)
{
cin >> fruit >> place >> m;
A[place][fruit] += m;
}
map <string, map<string, int> > :: iterator iter1;//
for (iter1 = A.begin(); iter1 != A.end(); iter1++)
{
cout << iter1->first << endl;
map<string, int> :: iterator iter2;//2个的区别
for (iter2 = iter1->second.begin(); iter2 != iter1->second.end(); iter2++)
{
cout << " |----" << iter2->first << "(" << iter2->second << ")" << endl;
}
}
}
return 0;
}