hdu 1263 水果
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)
爱上结构体了!!!!!!
注意输出格式就行了!!!!!!
代码:
#include <iostream>
#include <cstring>
#include <string>
#include <iomanip>
#include <algorithm>
using namespace std; struct dot
{
string s,t;
int n;
}st[1000];
int cmp(dot x,dot y)
{
if(x.t!=y.t)
return x.t<y.t;
else
return x.s<y.s;
}
int main()
{ int i,j,k,m,T;
cin>>T;
k=0;
while(T--)
{cin>>m;
for(i=0;i<m;i++)
cin>>st[i].s>>st[i].t>>st[i].n;
sort(st,st+m,cmp); for(i=m-1;i>0;i--)
{
if(st[i].s==st[i-1].s&&st[i].t==st[i-1].t)
st[i-1].n+=st[i].n;
}
if(k)cout<<endl;
cout<<st[0].t<<endl<<" |----"<<st[0].s<<"("<<st[0].n<<")"<<endl;
for(i=1;i<m;i++)
{ if(st[i].t==st[i-1].t&&st[i].s!=st[i-1].s)
cout<<" |----"<<st[i].s<<"("<<st[i].n<<")"<<endl;
else if(st[i].t!=st[i-1].t)
cout<<st[i].t<<endl<<" |----"<<st[i].s<<"("<<st[i].n<<")"<<endl;
} k++;
}
return 0;
}
hdu 1263 水果的更多相关文章
- hdu 1263 水果 【二维map】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 题目大意: Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ ...
- 题解报告:hdu 1263 水果
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营 ...
- HDU 1263(水果统计 **)
题意是对水果的产地和种类进行统计再按格式输出. 代码如下: #include <bits/stdc++.h> using namespace std; struct node { ],pl ...
- hdu 1263 水果 结构的排序+sort自定义排序
水果 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- HDU 1263 水果 结构体排序
解题报告:一个结构体排序的题,用了一个运算符重载,要注意的是不同的地方可能会产相同的水果,一开始没注意. #include<cstdio> #include<cstring> ...
- hdu 1263 水果 (嵌套 map)
水果Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...
- HDU 1263 水果 (STL map)
水果 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...
- STL || HDU 1263 水果
map可以映射map…… 然后在map里面会自己排序 惊了 注意输出格式 回车的输出 #include <iostream> #include <cstdio> #includ ...
- ACM 水果 hdu 1263 一题多解
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1263 文章末有相应的一些测试数据供参考. 传统的数组解题方式 思路一: 三种属性的数据放在一个结构体里面, ...
随机推荐
- maven, sesame, openrdf, eclipse 的初始学习
初始学习如下: http://rdf4j.org/sesame/tutorials/getting-started.docbook?view
- ASP.NET MVC 4.0的Action Filter
有时候你想在调用action方法之前或者action方法之后处理一些逻辑,为了支持这个,ASP.NET MVC允许你自定义创建action过滤器.Action过滤器是自定义的Attributes,用来 ...
- python之6-5偏函数
functools.partial 偏函数的作用是简化操作,简化什么操作呢?就是当我们有一个已知函数A,且这个函数包含有某个或多个参数A1,通过固定这个参数A1,我们可以自己编写一个新函数B,来减少代 ...
- 查看服务器IP连接数之主要命令(在服务器受攻击时用)
查看TCP几种状态的总数 netstat -n | awk '/^tcp/ {++S[$NF]} END {fo (a in S). print a, S[a]}' 按IP查看连接数排序 netsta ...
- ASP.ENT中上一篇和下一篇
前台页面:<div class="mtgz_prev_next"> <p> <span class="textcolor ...
- 转:使用linq to sql 随机取一行数据的方法
原文地址:http://outofmemory.cn/code-snippet/1760/usage-linq-to-sql-suiji-take-yixing-data-method 虽然这看来已经 ...
- 安卓,通过本地应用分享到微信、facebook等
别的不说了,直接上代码. 支持分享到微信.微博.facebook.twitter package com.example.shareSample; import java.util.List; imp ...
- JAVA并发实现三(线程的挂起和恢复)
package com.subject01; /** * 通过标识位,实现线程的挂起和回复 * com.subject01.AlternateSuspendResume.java * @author ...
- 如何改变Myeclipse编辑区背景色
编辑窗口右键单击——>Preferences——>General加号——>Editors加号——>点Text Editors字样——>右下窗口选Backgroud col ...
- poj 2100 Graveyard Design(尺取法)
Description King George has recently decided that he would like to have a new design for the royal g ...