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. MongoDB学习笔记~监控Http请求的消息链

    在微服务架构里,你的一个任务可以需要经过多次中转,去多个接口获取数据,而在这个过程中,出现问题后的解决就成了一个大难点,你无法定位它的问题,这时,大叔的分布式消息树就出现了,费话不多说,主要看一下实现 ...

  2. AJPFX简述abstract class和interface的区别

    含有abstract修饰符的class即为抽象类,abstract类不能创建的实例对象.含有abstract方法的类必须定义为abstract class,abstract class类中的方法不必是 ...

  3. iOS 音频视频制作

    --iOS多媒体 概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制, ...

  4. iOS 利用UIWebView与JavaScript交互的最简单办法

    这里说的是针对iOS的!并且方法很简单!!并且验证可行的!!! 1, UIWebView调用 JavaScript 的函数: NSString* strValue = [webView stringB ...

  5. 【python】入门级识别验证码

    前情:这篇文章所提及的内容是博主上个暑假时候做的,一直没有沉下心来把自己的心得写在纸面上,所幸这个假期闲暇时候比较多,想着能写多少是多少,于是就有了此篇. 验证码?我也能破解? 关于验证码的介绍就不多 ...

  6. 如何在Ubuntu里安装Helm

    Helm是什么?在战网上玩过暗黑破坏神2代的程序员们应该还记得,Helm是国度的意思. 而在计算机领域,Helm是什么? Helm是Kubernetes的一个包管理工具,有点像nodejs的npm,U ...

  7. 封装addClass 、 removeClass

    <script> window.onload = function() { var oDiv = document.getElementById('div1'); var oDiv2 = ...

  8. 剑指Offer(Python)

    014-链表中倒数第k个结点 用快慢指针:p2比p1先走到k:间隔了k-1)步,然后再一起走,当p2为最后一个时,p1就为倒数第k个数 class ListNode: def __init__(sel ...

  9. svn 设置代理

    Memory4Young Do Not Repeat Yourself! SVN —— 如何设置代理 如果在使用SVN下载外网的资源时,出现这样的提示:No such host is known. 或 ...

  10. 框架—Mybatis搭建

    1:导包 完整jar包:mybatis核心包+依赖包+mysqljdbc驱动包 2. 建库建表 3.实体类 4.映射文件 一般dao的包下 5.主配置文件(mybatisconfig.xml) 一般s ...