描述

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. java解析XML之DOM解析和SAX解析(包含CDATA的问题)

    Dom解析功能强大,可增删改查,操作时会将XML文档读到内存,因此适用于小文档: SAX解析是从头到尾逐行逐个元素解析,修改较为不便,但适用于只读的大文档:SAX采用事件驱动的方式解析XML.如同在电 ...

  2. 统计Visual Studio项目的代码行数

    原文转自 https://blog.csdn.net/tyc129/article/details/74279806 使用Visual Studio 自带的在文件中查找功能中的正则表达式实现代码统计功 ...

  3. 简谈const限定符

    const修饰的数据类型是常量类型,常量类型的对象和变量在定义初始化后是不能被更新的.其实只用记住这一个概念,就可以明白const操作对象的方法. 1)定义const常量 最简单的: const in ...

  4. hardseed

    hardseed https://github.com/yangyangwithgnu/hardseed

  5. [转载]关于python字典类型最疯狂的表达方式

    一个Python字典表达式谜题 让我们探究一下下面这个晦涩的python字典表达式,以找出在python解释器的中未知的内部到底发生了什么. # 一个python谜题:这是一个秘密 # 这个表达式计算 ...

  6. Ruby-Clamp

    require "clamp" class ClampTest < Clamp::Command # 1.命令行的参数使用主要分两类,一种是参数名称后面带参数值的方式, #我 ...

  7. mysql 安装和配置

    mysql 安装: 在命令行输入 sudo apt-get install mysql-server  安装过程中会跳出来一个窗口,输入数据库root用户的密码(必须输入密码) 安装完成后 通过 my ...

  8. [ python ] 类中的一些特殊方法

    item系列 __getitem__(self, item) 对象通过 object[key] 触发 __setitem__(self, key, value) 对象通过 object[key] = ...

  9. leetcode 141 142. Linked List Cycle

    题目描述: 不用辅助空间判断,链表中是否有环 /** * Definition for singly-linked list. * struct ListNode { * int val; * Lis ...

  10. Go语言中的匿名函数和闭包的样子

    1). 函数也是值,可以像普通值那样,传来传去: 2). 匿名函数: 3). 函数的类型,类似于:func(float64,float64) float64 ===================== ...