List the Books
描述
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.
输入
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.
输出
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.
样例输入
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
样例输出
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 <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
using namespace std;
typedef struct node
{
string name;
int year,price;
}node;
bool cmp(node a,node 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 cma(node a,node 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 cmb(node a,node 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,m,j,k,i,s,h;
node t[];
string ss;k=;
while(scanf("%d",&n),n)
{
if(k!=) printf("\n");
for(i=;i<n;i++)
{
cin>>t[i].name >>t[i].year >>t[i].price;
}
cin>>ss;
if(ss[]=='N')
sort(t,t+n,cmp);
else if(ss[]=='Y')
sort(t,t+n,cma);
else
sort(t,t+n,cmb);
k++;
for(j=;j<n;j++)
{
cout<<t[j].name<<" "<<t[j].year<<" "<<t[j].price<<endl;
}
}
}
List the Books的更多相关文章
- 7 Must Read Python Books
7 Must Read Python Books I started learning Python just two years ago. Coming from a C++ and Java ba ...
- TCP/IP BOOKS
TCP/IP Fundamentals for Microsoft Windows: Overview https://technet.microsoft.com/en-us/library/bb72 ...
- UVa 714 Copying Books(二分)
题目链接: 传送门 Copying Books Time Limit: 3000MS Memory Limit: 32768 KB Description Before the inventi ...
- LightOJ1283 Shelving Books(DP)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1283 Description You are a librarian ...
- 抄书 Copying Books UVa 714
Copying Books 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/B 题目: Descri ...
- [LintCode] Copy Books 复印书籍
Given an array A of integer with size of n( means n books and number of pages of each book) and k pe ...
- JSTL标签出错:<c:forEach var="book" items="${requestScope.books}" varStatus="status">
今天在运行书里的JSTL标签代码的时候出错,总结一下: 问题1.The JSP specification requires that an attribute name is preceded by ...
- A Year Of Books - 2016 Javaer书单
A Year Of Books - 2016 Javaer书单 (PS:欢迎留言推荐,很多来自白衣大哥的推荐) 1. OS & Networking <编码 : 隐匿在计算机软硬件背后的 ...
- A Personal Selection of Books on E lectromagnetics and Computational E lectromagnetics---David B. Davidson
链接. General Books on Electromagnetics When our department recently reviewed our junior-level text, w ...
- 【NOIP提高组2015D2T1】uva 714 copying books【二分答案】——yhx
Before the invention of book-printing, it was very hard to make a copy of a book. All the contents h ...
随机推荐
- hdu 2795 Billboard(线段树+单点更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others ...
- ThinkPHP5 模型 - 事务支持
使用事务之前,先确保数据库的存储引擎支持事务操作. MyISAM:不支持事务,主要用于读数据提高性能 InnoDB:支持事务.行级锁和并发 Berkeley DB:支持事务 ThinkPHP5 使用事 ...
- 使用XShell通过SSH访问Google谷歌云服务器方法
1:先用Xshell创建个密钥 下一步到这里,这个名称要记得,谷歌后台要用的. 把这里的公钥复制出来,当然最好也可以备份下. 2:到谷歌后台去添加ssh,然后就能连接了. 复制刚才生成的公钥,在谷歌云 ...
- HTML5 一篇就够的中文教程
HTML5 是近十年来 Web 开发标准最巨大的飞跃.HTML5 并非仅仅用来表示 Web 内容,它将 Web 带入一个成熟的应用平台,在 HTML5 平台上,视频.音频.图象.动画,以及同电脑的交互 ...
- aspxpivotgrid排序
protected virtual void SetSortBySummary() { foreach (PivotGridField field in grid.Fields) { if (fiel ...
- JQuery判断一个元素下面是否有内容或者有某个标签
网站开发时,我们时常需要把没有内容的标签隐藏或者去掉.在用JQ有两种好的解决办法: 一.判断文本是否为空 var jqObj = $(this);if(jqObj.text().trim()){ // ...
- Android各层推荐开发书籍及参考资料!!!
Android各层推荐开发书籍及参考资料 转自:http://blog.csdn.net/fancylovejava/article/details/8657058 Android系统按照架构来说一共 ...
- thinkphp+dwz完成的一个号码查询小系统
基于网友的例子(http://www.thinkphp.cn/extend/450.html),改进完成一个电话号码查询管理系统.基于thinkphp+dwz完成的电话号码查询小系统,主要改进与功能如 ...
- STL容器 -- Priority_Queue
核心:和队列相似,但优先队列中的 “下一个元素” 指的是 “优先级最高” 的元素. 头文件:#include<queue> 普通类型的构造方法: priority_queue<int ...
- 洛谷P3901 数列找不同 [莫队]
题目传送门 题目描述 现有数列 A_1,A_2,\cdots,A_NA1,A2,⋯,AN ,Q 个询问 (L_i,R_i)(Li,Ri) , A_{Li} ,A_{Li+1},\cdots, ...