描述

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. lnmp、lamp、lnmpa一键安装包(Updated: 2016-4-12)

    lnmp.lamp.lnmpa一键安装包(Updated: 2016-4-12)   文章目录 脚本特性 安装步骤 如何添加虚拟主机? 如何删除虚拟主机? 如何管理ftp账号? 数据备份 如何管理服务 ...

  2. 使用EL表达式需要注意的

    1.表达式与Java无关,表达式都是以${开始,以}结束. 2.EL访问java变量不能直接访问,因为得不到数据,要访问数据,需要将其放到作用域中.而使用<%=java变量%>可以访问ja ...

  3. Python模块学习 - IPy

    简介 在IP地址规划中,涉及到计算大量的IP地址,包括网段.网络掩码.广播地址.子网数.IP类型等,即便是专业的网络人员也要进行繁琐的计算,而IPy模块提供了专门针对IPV4地址与IPV6地址的类与工 ...

  4. linux 命令行远程登录 后台运行命令的方法

    linux 命令行远程登录 后台运行命令的方法 http://blog.csdn.net/isuker/article/details/55061595 Linux 技巧:让进程在后台可靠运行的几种方 ...

  5. Atom:优雅迷人的编辑神器

    对于热爱markdown写作的人来说,Atom同样是一款拥有无穷魅力的写作软件.我不怕它无法满足你的需求,就怕你不给一个机会了解它,那么,这将是一场遗憾的错过. 大学的时候,坊间对那些编程高手有一个令 ...

  6. 文件上传实现ajax假异步

    $.ajaxFileUpload({ url : getSitePath()+'/jlyElderly/doUpdateImage', secureuri : false,//是否需要安全协议 fil ...

  7. 关于JqueryEasyUI插件—Tab,默认选中某个面板 如果不明显指定的话,第一个就是被选中的

    如果不明显指定的话,第一个就是被选中的,你可以通过data-options="selected:true"指定默认选中

  8. django “如何”系列1:如何使用REMOTE_USER(远程用户)进行认证

    这节主要介绍当web服务器使用了REMOTE_USER的时候,该如何在你的django应用中使用外部的认证源,远程用户主要见于企业内部网,主要使用单点登录解决方案. 在django中,REMOTE_U ...

  9. POJ 1984 Navigation Nightmare(二维带权并查集)

    题目链接:http://poj.org/problem?id=1984 题目大意:有n个点,在平面上位于坐标点上,给出m关系F1  F2  L  D ,表示点F1往D方向走L距离到点F2,然后给出一系 ...

  10. Intellij idea的maven依赖图

    Intellij idea下查看maven的依赖图与eclipse有所不同.下面简单介绍一下Intellij下maven的查看使用. 使用场景 当你想查看maven依赖的jar都有哪些,是否有冲突,冲 ...