HDU 1263 水果 (STL中的map嵌套)

水果

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1362    Accepted Submission(s): 532


Problem Description
夏天来了~~好开心啊,呵呵,好多好多水果~~
Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了.
 

 

Input
第一行正整数N(0每组测试数据的第一行是一个整数M(0
 

 

Output
对于每一组测试数据,请你输出一份排版格式正确(请分析样本输出)的水果销售情况明细表.这份明细表包括所有水果的产地,名称和销售数目的信息.水果先按产地分类,产地按字母顺序排列;同一产地的水果按照名称排序,名称按字母顺序排序.
两组测试数据之间有一个空行.最后一组测试数据之后没有空行.
 

 

Sample Input
1
5
apple shandong 3
pineapple guangdong 1
sugarcane guangdong 1
pineapple guangdong 3
pineapple guangdong 1
 

 

Sample Output
guangdong
|----pineapple(5)
|----sugarcane(1)
shandong
|----apple(3)
 
 
 
#include <set>
#include
#include
#include
#include
#include
#include
#include
#include
#include <string>
#include
#include
#include
#include
#include
#include
#include
#include
#include

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 aint 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;
}

转载于:https://www.cnblogs.com/qiufeihai/archive/2012/03/20/2407571.html

你可能感兴趣的:(HDU 1263 水果 (STL中的map嵌套))