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 ...
随机推荐
- h5-16-插入SVG图片
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 创建表规范 lob 字段
ORAClce 11g 提供如下特性: BasicfileOracle10g 及之前版本被称为basicfile Securefile11g中新增securefile 优点:集中写入缓存(WGC),4 ...
- 使用json传输数组实例
client.php <?php //遍历数组元素,并将元素转码 function array_iconv($data, $in_charset='GBK', $out_charset='UTF ...
- jmeter压测--从文本中读取参数
由于之前从数据库获取查询结果作为请求的入参(使用场景:测试一个接口并发处理数据的能力,并且每次请求传入的参数都要不同.),会一定程度上造成对数据库的压测,在没有完全搞清楚多线程之间参数的传递之前,我们 ...
- SpringBoot 2.x (7):拦截器
类似以前SpringMVC的拦截器,但也有一些区别 SpringBoot的拦截器有两种方式: 第一种方式:过时的方式,适用于SpringBoot1.x的方式 package org.dreamtech ...
- 响应式布局 max-device-width 与 max-width 的区别
闲来没事,研究了一下多屏适配和响应式布局的 CSS. 第一种写法 @media screen and (max-device-width: 320px) { } @media screen and ( ...
- ssl证书过期问题解决
1,ssl证书失效现象 小程序debug有如下证书无效信息: 浏览器访问https://ic-park.net:30001/indoornav/callFunction1.php 提示证书风险. 2, ...
- iOS猜拳游戏源码
利用核心动画和Quartz2D做的一个小游戏.逻辑十分简单. 源码下载:http://code.662p.com/<ignore_js_op> 详细说明:http://ios.662p.c ...
- Java实现Web页面前数字字母验证码实现
最近公司做项目开发中用到了验证码实现功能,将实现代码分享出来, 前段页面实现代码: 为了表达清晰,样式部分代码去掉了,大家根据自己的需求,自己添加样式. 页面JS代码:触发变动验证码改变的JS 后台 ...
- cocos creator 小记
一个游戏场景有若干个节点组成,这些包括渲染节点,UI节点. 这里弱化了Layer层的概念. 一个游戏由若干个场景组件. 每个节点由若干个组件和若干子节点组成. 例如UI节点中的 按钮节点.子节点有 ...