描述

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的更多相关文章

  1. 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 ...

  2. TCP/IP BOOKS

    TCP/IP Fundamentals for Microsoft Windows: Overview https://technet.microsoft.com/en-us/library/bb72 ...

  3. UVa 714 Copying Books(二分)

    题目链接: 传送门 Copying Books Time Limit: 3000MS     Memory Limit: 32768 KB Description Before the inventi ...

  4. LightOJ1283 Shelving Books(DP)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1283 Description You are a librarian ...

  5. 抄书 Copying Books UVa 714

    Copying  Books 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/B 题目: Descri ...

  6. [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 ...

  7. JSTL标签出错:<c:forEach var="book" items="${requestScope.books}" varStatus="status">

    今天在运行书里的JSTL标签代码的时候出错,总结一下: 问题1.The JSP specification requires that an attribute name is preceded by ...

  8. A Year Of Books - 2016 Javaer书单

    A Year Of Books - 2016 Javaer书单 (PS:欢迎留言推荐,很多来自白衣大哥的推荐) 1. OS & Networking <编码 : 隐匿在计算机软硬件背后的 ...

  9. 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 ...

  10. 【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 ...

随机推荐

  1. JS中的日期内置函数

    用JS中的日期内置函数实现在页面显示:“今天是:2013年9月26日14:32:45”. var date=new Date(Date.parse('9/26/2013 14:32:45'));   ...

  2. Xmind 8 update5 破解

    Step 1. Download XMind Step 2. Run XMind at least once after installation, xmind will init the confi ...

  3. java===java基础学习(10)---对象构造

    重载 如果多个方法有相同的名字,不同的参数,便产生了重载.编译器必须挑选出具体执行哪个方法,他通过用各个方法给出的参数类I型那个与特定方法调用所使用的值类型进行匹配来挑选出相应的方法.如果编译器找不到 ...

  4. markdown===在新窗口中打开网址的解决办法,以及其他遗留问题!

    [超链接文字](url){:target="_blank"} 遗留问题: 如何设置图片的尺寸 我的复选框一直不生效,why? 公式 $$ 公式 $$ 不生效 如何设置代码块的背景颜 ...

  5. XMLDocument 方法中实现post发送消息

    XMLDocument 方法中实现post发送消息

  6. dockerfile实例--安装nginx

    [root@localhost ~]# vi Dockerfile //ADD FROM centos_with_net MAINTAINER frankie onez0714@.com RUN yu ...

  7. C# 笔记——数据类型

    一张图读懂C#数据类型:

  8. WdatePicker做出onchange效果

    WdatePicker({onpicking: function (dp) {if (dp.cal.getDateStr() != dp.cal.getNewDateStr()) { Func(dp. ...

  9. JAVA中静态块、静态变量加载顺序详解

    http://blog.csdn.net/mrzhoug/article/details/51581994 一般顺序:静态块(静态变量)——>成员变量——>构造方法——>静态方法

  10. 《java并发编程实战》读书笔记12--原子变量,非阻塞算法,CAS

    第15章 原子变量与非阻塞同步机制 近年来,在并发算法领域的大多数研究都侧重于非阻塞算法,这种算法用底层的原子机器指令(例如比较并交换指令)代替锁老确保数据在并发访问中的一致性. 15.1 锁的劣势 ...