水果

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做的
代码:
 #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef struct
{
string ad,na; /*ad-->adress,na--->name*/
int cnt;
}go;
int cmp(go const a, go const b)
{
if(a.ad<b.ad) return ;
if(a.ad>b.ad) return ;
else
{
if(a.na<b.na) return ;
return ;
}
}
int main()
{
int t,ss;
vector<go>st;
vector<go>::iterator it;
go tem;
scanf("%d",&t);
while(t--)
{
st.clear();
scanf("%d",&ss);
while(ss--)
{
cin>>tem.na>>tem.ad>>tem.cnt;
if(st.empty())
st.push_back(tem);
else
{
for( it=st.begin() ;it!=st.end() ; it++)
{
if((it->ad==tem.ad)&&(it->na==tem.na))
{
it->cnt+=tem.cnt;
break;
}
}
if(it==st.end())
{
st.push_back(tem);
}
}
}
sort(st.begin(),st.end(),cmp);
for( it=st.begin() ;it!=st.end() ; it++)
{
if(it==st.begin()||(it-)->ad!=it->ad)
cout<<it->ad<<endl;
cout<<" |----"<<it->na<<"("<<it->cnt<<")"<<endl;
}
if(t)cout<<endl;
}
return ;
}
 

HDUOJ----1263水果的更多相关文章

  1. hdu 1263 水果 【二维map】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 题目大意: Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ ...

  2. HDOJ.1263 水果(map)

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

  3. 题解报告:hdu 1263 水果

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 Problem Description 夏天来了~~好开心啊,呵呵,好多好多水果~~ Joe经营 ...

  4. hdu 1263 水果

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

  5. HDU 1263(水果统计 **)

    题意是对水果的产地和种类进行统计再按格式输出. 代码如下: #include <bits/stdc++.h> using namespace std; struct node { ],pl ...

  6. hdu 1263 水果 结构的排序+sort自定义排序

    水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  7. HDU 1263 水果 结构体排序

    解题报告:一个结构体排序的题,用了一个运算符重载,要注意的是不同的地方可能会产相同的水果,一开始没注意. #include<cstdio> #include<cstring> ...

  8. hdu 1263 水果 (嵌套 map)

    水果Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...

  9. HDU 1263 水果 (STL map)

    水果 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  10. 【HDOJ】1263 水果

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

随机推荐

  1. 字符测试篇isalnum isalpha isascii iscntrl isdigit isgraphis islower isprint isspace ispunct isupper isxdigit

    isalnum(测试字符是否为英文或数字) 相关函数 isalpha,isdigit,islower,isupper 表头文件 #include<ctype.h> 定义函数 int isa ...

  2. 聊聊并发(四)——深入分析ConcurrentHashMap

    线程不安全的HashMap 因为多线程环境下,使用HashMap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap,如以下代码   final HashM ...

  3. 使用supervisor过程的坑

    1.安装:由于使用的是公司的虚拟机,所以使用pip install supervisor的过程遇到很多权限问题. 中间尝试使用sudo pip install supervisor的方式安装,但是使用 ...

  4. 【BZOJ】【2219】数论之神

    中国剩余定理+原根+扩展欧几里得+BSGS 题解:http://blog.csdn.net/regina8023/article/details/44863519 新技能get√: LL Get_yu ...

  5. DDR SDRAM芯片DQS的作用以及读写DQS/DQ对齐方式不同的原因

    节选内容转载自https://www.design-reuse.com/articles/13805/the-love-hate-relationship-with-ddr-sdram-control ...

  6. CentOS6.5升级autoconf版本 Autoconf version 2.64 or higher is required

    安装软件时提示说需要Autoconf 2.64或更高的版本 [root@BobServerStation twemproxy]# autoconf configure.ac:8: error: Aut ...

  7. jQuery多媒体播放器插件jQuery Media Plugin使用方法

    jQuery Media Plugin是一款基于jQuery的网页媒体播放器插件,它支持大部分的网络多媒体播放器和多媒体格式,比如:Flash, Windows Media Player, Real ...

  8. 让 IE6, 7和 8支持CSS3的HTC文件补丁

    让 IE6, 7和 8支持CSS3 IE6,7并不支持CSS3的属性,IE8也不能很好的支持CSS3.但是有一个小脚本能够做到,它可以让IE支持CSS3,包括:border-radius (round ...

  9. word图片自动编号与引用(转)

    http://blog.csdn.net/hunauchenym/article/details/5915616 用Word时,可能会遇到文中使用了大量的图片的情况,这时,若采用手动为图片编号的方法, ...

  10. linux 命令行选项

    命令行选项风格 1.原始unix风格     a.命令行选项以连字符'-'开头,后跟单个字符表示选项,选项后面跟着取值,如:mysql -hlocalhost b.选项不带取值的,可以组合在一起,如: ...