Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2791 Accepted Submission(s): 1056
Problem Description
夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了.
Input
第一行正整数N(0<N<=10)表示有N组测试数据. 每组测试数据的第一行是一个整数M(0<M<=100),表示工有M次成功的交易.其后有M行数据,每行表示一次交易,由水果名称(小写字母组成,长度不超过80),水果产地(小写字母组成,长度不超过80)和交易的水果数目(正整数,不超过100)组成.
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)
Source
C++ STL做的
代码:
1 #include<iostream>
2 #include<algorithm>
3 #include<string>
4 #include<vector>
5 using namespace std;
6 typedef struct
7 {
8 string ad,na; /*ad-->adress,na--->name*/
9 int cnt;
10 }go;
11 int cmp(go const a, go const b)
12 {
13 if(a.ad<b.ad) return 1;
14 if(a.ad>b.ad) return 0;
15 else
16 {
17 if(a.na<b.na) return 1;
18 return 0;
19 }
20 }
21 int main()
22 {
23 int t,ss;
24 vector<go>st;
25 vector<go>::iterator it;
26 go tem;
27 scanf("%d",&t);
28 while(t--)
29 {
30 st.clear();
31 scanf("%d",&ss);
32 while(ss--)
33 {
34 cin>>tem.na>>tem.ad>>tem.cnt;
35 if(st.empty())
36 st.push_back(tem);
37 else
38 {
39 for( it=st.begin() ;it!=st.end() ; it++)
40 {
41 if((it->ad==tem.ad)&&(it->na==tem.na))
42 {
43 it->cnt+=tem.cnt;
44 break;
45 }
46 }
47 if(it==st.end())
48 {
49 st.push_back(tem);
50 }
51 }
52 }
53 sort(st.begin(),st.end(),cmp);
54 for( it=st.begin() ;it!=st.end() ; it++)
55 {
56 if(it==st.begin()||(it-1)->ad!=it->ad)
57 cout<<it->ad<<endl;
58 cout<<" |----"<<it->na<<"("<<it->cnt<<")"<<endl;
59 }
60 if(t)cout<<endl;
61 }
62 return 0;
63 }