List the Books


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Jim is fond of reading books, and he has so many books that sometimes it's hard for him to manage them. So he is asking for your help to solve this problem.

Only interest in the name, press year and price of the book, Jim wants to get a sorted list of his books, according to the sorting criteria.

Input

The problem consists of multiple test cases.

In the first line of each test case, there's an integer n that specifies the number of books Jim has. n will be a positive integer less than 100. The next n lines give the information of the books in the format Name Year PriceName will be a string consisting of at most 80 characters from alphabet, Year and Price will be positive integers. Then comes the sorting criteria, which could be NameYear or Price.

Your task is to give out the book list in ascending order according to the sorting criteria in non-ascendent order.

Note: That Name is the first criteria, Year is the second, and Price the third. It means that if the sorting criteria is Year and you got two books with the same Year, you'd sort them according to their Name. If they equals again, according to their Price. No two books will be same in all the three parameters.

Input will be terminated by a case with n = 0.

Output

For each test case, output the book list, each book in a line. In each line you should output in the format Name Year Price, the three parameters should be seperated by just ONE space.

You should output a blank line between two test cases.

Sample Input

3
LearningGNUEmacs 2003 68
TheC++StandardLibrary 2002 108
ArtificialIntelligence 2005 75
Year
4
GhostStory 2001 1
WuXiaStory 2000 2
SFStory 1999 10
WeekEnd 1998 5
Price
0

Sample Output

TheC++StandardLibrary 2002 108
LearningGNUEmacs 2003 68
ArtificialIntelligence 2005 75 GhostStory 2001 1
WuXiaStory 2000 2
WeekEnd 1998 5
SFStory 1999 10
 #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct book{
string name;
int year;
int price;
};
bool cmpName(const book &a, const book &b){
if(a.name != b.name)
return a.name < b.name;
else if(a.year != b.year)
return a.year < b.year;
else
return a.price < b.price;
} bool cmpYear(const book &a, const book &b){
if(a.year != b.year)
return a.year < b.year;
else if(a.name != b.name)
return a.name < b.name;
else
return a.price < b.price;
} bool cmpPrice(const book &a, const book &b){
if(a.price != b.price)
return a.price < b.price;
else if (a.name != b.name)
return a.name < b.name;
else
return a.year < b.year;
} int main(){
int n;
vector<book> v;
book bk;
string sorting;
int line = ;
while(cin >> n){
if(n == )
break;
v.clear();
line++;
for(int i = ; i < n; i++){
cin >> bk.name >> bk.year >> bk.price;
v.push_back(bk);
}
cin >> sorting;
if(sorting == "Name")
sort(v.begin(), v.end(), cmpName);
else if (sorting == "Year")
sort(v.begin(), v.end(), cmpYear);
else
sort(v.begin(), v.end(), cmpPrice);
if(line != )
cout << endl;
for(int i = ; i < n; i++)
cout << v[i].name << " " << v[i].year << " " << v[i].price << endl;
}
return ;
}
 

zoj 2727 List the Books的更多相关文章

  1. ZOJ 2002 Copying Books 二分 贪心

    传送门:Zoj2002 题目大意:从左到右把一排数字k分,得到最小化最大份,如果有多组解,左边的尽量小. 思路:贪心+二分(参考青蛙过河). 方向:从右向左. 注意:有可能最小化时不够k分.如     ...

  2. ZOJ 4067 - Books - [贪心][2018 ACM-ICPC Asia Qingdao Regional Problem J]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4067 题意: 给出 $n$ 本书(编号 $1 \sim n$), ...

  3. 【ZOJ 4067】Books

    [链接] 我是链接,点我呀:) [题意] [题解] 统计a中0的个数cnt0 然后m减去cnt0 因为这cnt0个0是一定会取到的. 如果m==0了 那么直接找到数组中的最小值mi 输出mi-1就好 ...

  4. ZOJ List the Books 水~

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1727 题目大意: 给你书名.出版时间.价格,让你按照一定的顺序排序.. 其中题 ...

  5. ZOJ 4067 Books (2018icpc青岛J) (贪心)

    题意 给你一个长度为n的数组,代表每一个物品的价格.你有一个初始钱数\(x\),采用以下方法贪心: 从\(1\)到\(n\)扫一遍,如果\(x\)不比\(a[i]\)小,就买下它,买不起就跳过. 给你 ...

  6. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  7. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  8. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  9. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

随机推荐

  1. 129 Sum Root to Leaf Numbers 求根叶数字总和

    给定一个只包含 0-9 数字的二叉树,每个根到叶的路径可以代表一个数字.例如,从根到叶路径 1->2->3则代表数字 123.查找所有根到叶数字的总和.例如,    1   / \  2  ...

  2. STM32HAL库学习之前言

    HAL库:HAL 的全称是: Hardware Abstraction Layer (硬件抽象层) ,是ST最新推荐的库.包括基本库和扩展库(功能外展):三种编程模型(轮询.中断和 DMA) 灵活的回 ...

  3. (020)[虚拟系统]Win7网络连接红叉(无解决)

    该虚拟机在重装主系统前是可以连接网络的,主系统重新安装以后,导入新安装的VM以后,网络图标显示红叉. 查看设备管理,显示没有安装以太网驱动. 重新安装 Vmware Tools,未果.VMware官网 ...

  4. POST 传参

    $http.post("../jzgCar_listAllJzgCar.do?data={parentId:"+value+"}") value 是参数,都是双 ...

  5. AJPFX总结java开发常用类(包装,数字处理集合等)(一)

    一:首谈java中的包装类 Java为基本类型提供包装类,这使得任何接受对象的操作也可以用来操作基本类型,直接将简单类型的变量表示为一个类,在执行变量类型的相互转换时,我们会大量使用这些包装类.jav ...

  6. SpringBoot 2.x (8):模板引擎

    SpringBoot中有很多的starter:本质是多个JAR包集合 比如我们常用的: <dependency> <groupId>org.springframework.bo ...

  7. 深入理解Java的整型类型:如何实现2+2=5?

    先看下这段神奇的Java代码: public static void main(String[] args) throws Exception { doSomethingMagic(); System ...

  8. Android(java)学习笔记184:多媒体之 MediaPlayer使用

    MediaPlayer类可用于控制音频/视频文件或流的播放.关于如何使用这个类的方法还可以阅读VideoView类的文档. 1.MediaPlayer 状态图       对播放音频/视频文件和流的控 ...

  9. zabbix实现自动发现功能添加磁盘监控

    zabbix实现对磁盘动态监控 - Lenwood 原文  http://www.cnblogs.com/baizhantang/p/3253246.html 主题 Linux命令 zabbix 前言 ...

  10. 谷歌 滚动条样式 scrollbar

    谷歌  滚动条样式 scrollbar main.less :: 是css3 最新的伪类 /*滚动条整体样式*/ ::-webkit-scrollbar { width: 10px; height: ...