水果

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

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)
 

本题可用二维map容器求解。

第一次写二维map,真是学到了!map容器还能这麽用~详解见代码注释。

AC代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
//定义二维map容器
map<string,map<string,int> > a;//注意此处两">"间要加空格
map<string,int> b;
int n,m; int main(){
string f,p;
int ans;
while(~scanf("%d",&n)){
while(n--){
a.clear();
b.clear();
cin>>m;
while(m--){
cin>>f>>p>>ans;
a[p][f]+=ans;//此处将产地放在前面方便输出
}
//定义两个map容器的前向迭代器
map<string,map<string,int> >::iterator i;//注意此处两">"间要加空格
map<string,int>::iterator j;
for(i=a.begin();i!=a.end();i++){
cout<<i->first<<endl;//输出产地
b=i->second;
for(j=b.begin();j!=b.end();j++){//输出b容器中保存的对应的水果和交易数量
cout<<" |----"<<j->first<<"("<<j->second<<")"<<endl;//注意输出格式,最好复制
}
}
if(n>)//注意换行符的输出
printf("\n");
}
}
return ;
}

HDOJ-1263的更多相关文章

  1. HDOJ.1263 水果(map)

    水果 点我跳转到题面 点我一起学习STL-MAP 题意分析 给出多组测试数据,每组数据有多条信息.分别是水果种类,地点,和水果数目.每组信息要按照样例输出,并且输出要按照地点->水果种类的字典序 ...

  2. 【HDOJ】1263 水果

    hash,使用stl map ac.学了find_if等强大的东西,第一次使用stl模板. #include <iostream> #include <cstdio> #inc ...

  3. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  5. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  7. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  8. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  9. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

  10. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

随机推荐

  1. OpenGL 与 GLSL 版本号

    来自:https://github.com/mattdesl/lwjgl-basics/wiki/GLSL-Versions You can use the #version command as t ...

  2. .Net Core表单定义

    创建表单 <form asp-controller="Account" asp-action="Login" asp-route-returnurl=&q ...

  3. MacOS 修改主机名

    修改主机名 sudo scutil --set HostName xxx 修改共享名 sudo scutil --set ComputerName xxx

  4. Recurrent neural networks are very powerful, because they combine two properties

    https://www.cs.toronto.edu/~hinton/csc2535/notes/lec10new.pdf Distributed hidden state that allows t ...

  5. Git 忽略上传文件设置 .gitignore exclude

    1.项目根目录下创建.gitignore vi .gitignore #输入需要忽略的文件,支持正则表达式, *.o *.exe*.pyc 可以用git status来检查是否生效 未添加文件前: M ...

  6. Multi-lingual Support

    Multi-lingual Support One problem with dealing with non-Latin characters programmatically is that, f ...

  7. leetcode 792. Number of Matching Subsequences

    Given string S and a dictionary of words words, find the number of words[i] that is a subsequence of ...

  8. MATLAB 2013b .m 文件关联

    使用绿色版的MATLAB无法自动关联.m文件,在网上查到的解决办法是,在MATLAB里运行如下命令: cwd=pwd; cd([matlabroot '\toolbox\matlab\winfun\p ...

  9. POJ 2485 Highways(最小生成树+ 输出该最小生成树里的最长的边权)

                                                                                                         ...

  10. POJ 1611 The Suspects (并查集+数组记录子孙个数 )

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 24134   Accepted: 11787 De ...