zoj 2727 List the Books
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 Price. Name 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 Name, Year 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的更多相关文章
- ZOJ 2002 Copying Books 二分 贪心
传送门:Zoj2002 题目大意:从左到右把一排数字k分,得到最小化最大份,如果有多组解,左边的尽量小. 思路:贪心+二分(参考青蛙过河). 方向:从右向左. 注意:有可能最小化时不够k分.如 ...
- 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$), ...
- 【ZOJ 4067】Books
[链接] 我是链接,点我呀:) [题意] [题解] 统计a中0的个数cnt0 然后m减去cnt0 因为这cnt0个0是一定会取到的. 如果m==0了 那么直接找到数组中的最小值mi 输出mi-1就好 ...
- ZOJ List the Books 水~
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1727 题目大意: 给你书名.出版时间.价格,让你按照一定的顺序排序.. 其中题 ...
- ZOJ 4067 Books (2018icpc青岛J) (贪心)
题意 给你一个长度为n的数组,代表每一个物品的价格.你有一个初始钱数\(x\),采用以下方法贪心: 从\(1\)到\(n\)扫一遍,如果\(x\)不比\(a[i]\)小,就买下它,买不起就跳过. 给你 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
随机推荐
- ios NSFileManager 用法详解
转自:http://blog.csdn.net/ios_che/article/details/7287266 iPhone文件系统NSFileManager讲解是本文要介绍的内容,主要是通过ipho ...
- B. Connecting Universities DFS,无向树
http://codeforces.com/problemset/problem/700/B 题意是,在一颗树中,有k个大学,要求两两匹配,他们之间的距离作为贡献,使得距离总和最大. 一开始的时候无从 ...
- PHP在不同页面间传递Json数据示例代码
gettest.php文件: <?php $value["name"]= urlencode("我的姓名"); $value["pass&quo ...
- CocoaPods安装遇到的坑。
//官方推荐地址 CocoaPods :http://code4app.com/article/cocoapods-install-usage cooped的安装 $(inherited) 报pod ...
- iOS中使用 Reachability 检测网络区分手机网络类型 WiFi 和2 3 4 G
如果你想在iOS程序中提供一仅在wifi网络下使用(Reeder),或者在没有网络状态下提供离线模式(Evernote).那么你会使用到Reachability来实现网络检测. 写本文的目的 了解Re ...
- Runtime理解
动态语言 OC是一门不折不扣的动态语言,所以它的很多机制都是动态运行时决定的.这点和C语言不一样,C语言是静态绑定,也就是编译后所有的一切都已经决定了.这一点和C语言的函数指针有些类似,很多时候函数指 ...
- centos系统iptables使用帮助
#如果只是想屏蔽IP的话“开放指定的端口”可以直接跳过.#屏蔽单个IP的命令是iptables -I INPUT -s 123.45.6.7 -j DROP#封整个段即从123.0.0.1到123.2 ...
- 最新精品 强势来袭 XP,32/64位Win7,32/64位Win8,32/64位Win10系统【国庆版版】
本系统是10月最新完整版本的Windows10 安装版镜像,Win10正式版,更新了重要补丁,提升应用加载速度,微软和百度今天宣布达成合作,百度成为Win10 Edge浏览器中国默认主页和搜索引擎,系 ...
- 千万千万不要运行的 Linux 命令
文中列出的命令绝对不可以运行,即使你觉得很好奇也不行,除非你是在虚拟机上运行(出现问题你可以还原),因为它们会实实在在的破坏你的系统.所以不在root等高级管理权限下执行命令是很好的习惯. 早晚有一天 ...
- easybcd 支持 windows 10 和 ubuntu 14.04 双系统启动
家里计算机系统 windows 10 全新安装. 原本是双系统的,还有一个ubuntu. windows 10 安装以后,恢复ubuntu就是问题了. (事后经验:请不要立刻安装bcd修改工具) 最初 ...