hdoj 1263 水果(map)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263

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)

 1     #include<iostream>
 2     #include<map>
 3     #include<string>
 4     using namespace std;
 5     int main()
 6     {
 7         int T;
 8         cin>>T;
 9         while(T--){
10             int n;
11             string fruit;
12             string add;
13             int num;
14             cin>>n;
15             map<string,map<string,int> >m;
16             while(n--){
17                 cin>>fruit>>add>>num;
18                 (m[add])[fruit] += num;
19             }
20             map<string,map<string,int> >::iterator key;
21             for(key = m.begin();key!=m.end();key++){
22                 cout<<key->first<<endl;
23                 map<string,int>::iterator i= (key->second).begin();
24                 for(;i!=(key->second).end();i++)
25                     cout<<"   |----"<<i->first<<"("<<i->second<<")"<<endl;
26                 }
27                 if(T>0){
28                     cout<<endl;
29             }
30         }
31     }
时间: 2024-08-28 03:38:22

hdoj 1263 水果(map)的相关文章

hdu 1263 水果(map)

水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3831    Accepted Submission(s): 1433 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以

题解报告:hdu 1263 水果

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了. Input 第一行正整数N(0<N<=10)表示有N组测试数据. 每组测试数据的第一行是一个整数M(0<M<=100),表示工有M次成功的

hdoj 5199 Gunner map

Gunner Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5199 Description Long long ago, there is a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds and n

Hdu 1263 水果

水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6986    Accepted Submission(s): 2748 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容

HDOJ 2072(map)

#include<cstdio> #include<iostream> #include<vector> #include<map> #include<queue> #include<algorithm> #include<deque> #include<cmath> #include<set> #include<cstring> #include<string> using

hdu 1263 水果 sort对结构体中字符串二级排序

#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; struct node { char name[90],place[90]; int num; }c[105]; bool cmp(node x,node y) { if(strcmp(x.place,y.place)<0) return true; if(strcmp(x.place,y.place)=

map嵌套

第一次使用map嵌套,做个纪念. HDU 1263 水果 http://acm.hdu.edu.cn/showproblem.php?pid=1263 题解:按照地名的字典序.水果的字典序.水果的数量这个顺序输出.题意很简单,关键是用map嵌套. 代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmath> 5 #include<algorithm&g

C++STL之ACM相关知识大全

vector 在STL 的头文件中定义了vector(向量容器模板类),vector容器以连续数组的方式存储元素序列,可以将vector 看作是以顺序结构实现的线性表.当我们在程序中需要使用动态数组时,vector 将会是理想的选择,vector 可以在使用过程中动态地增长存储空间. vector 模板类需要两个模板参数,第一个参数是存储元素的数据类型,第二个参数是存储分配器的类型,其中第二个参数是可选的,如果不给出第二个参数,将使用默认的分配器. 1.定义vector 向量对象的方法: vec

(map,c_str())水果 hdu1263

水果 http://acm.hdu.edu.cn/showproblem.php?pid=1263 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12167    Accepted Submission(s): 4844 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~Joe经营着一个不大的水果店.他