ZOJ List the Books 水~
来源:互联网 发布:淘宝万能评价语 编辑:程序博客网 时间:2024/05/16 08:33
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1727
题目大意:
给你书名、出版时间、价格,让你按照一定的顺序排序。。
其中题目会给出优先级最高的,剩下两个按书名优先级>出版时间>价格来排序。
思路:
练习sort重载的。。。
不过sort(book,book+n,cmp_by_name);的重载函数竟然不能用引用。。不然会cp好吧,我习惯写重载<运算符了。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAXN=100+2;struct Book{char name[MAXN];int year,price;}book[MAXN];bool cmp_by_name(Book a,Book b){int k=strcmp(a.name,b.name);if(k < 0)return true;else if(k > 0)return false;return a.year < b.year || (a.year==b.year && a.price<b.price);}bool cmp_by_price(Book a,Book b){if(a.price < b.price)return true;else if(a.price > b.price)return false;int k=strcmp(a.name,b.name);if(k < 0)return true;else if(k > 0)return false;return a.year<b.year;}bool cmp_by_year(Book a,Book b){if(a.year < b.year)return true;else if(a.year > b.year)return false;int k=strcmp(a.name,b.name);if(k < 0)return true;else if(k > 0)return false;return a.price<b.price;}int main(){int n;int kase=0;while(~scanf("%d",&n),n){if(kase++)puts("");for(int i=0;i<n;i++)scanf("%s%d%d",book[i].name,&book[i].year,&book[i].price);char cmd[20];scanf("%s",cmd);if(strcmp(cmd,"Name")==0)sort(book,book+n,cmp_by_name);else if(strcmp(cmd,"Year")==0)sort(book,book+n,cmp_by_year);else if(strcmp(cmd,"Price")==0)sort(book,book+n,cmp_by_price);for(int i=0;i<n;i++)printf("%s %d %d\n",book[i].name,book[i].year,book[i].price);}return 0;}
3 0
- ZOJ List the Books 水~
- zoj 2727 list the books
- ZOJ 2727List the Books
- ZOJ 2727 List the Books
- zoj 2727 List the Books(排序)
- ZOJ Problem Set - 2727 List the Books
- zoj 2727 List the Books(三级排序 = =水题)
- ZOJ2727 List the Books
- List the Books(sort)
- zoj2727-------------------List the Books 结构体排序
- Books List
- zoj 2727 List the Book
- ZOJ-2002 Copying Books
- Good books in list
- free e-books list
- Read-Books-List
- Machine Learning Books List
- the books about java
- Direct-attached storage (DAS)
- text-align简单理解
- hive 初始化运行流程
- [Linux]Fedora 20 MySQL安装配置
- 在Windows下的javah编译class文件找不到android.app.Activity的类文件
- ZOJ List the Books 水~
- Java--JDBC操作数据库
- js中匿名函数的N种写法
- 女神来了
- js call
- ZOJ-3542
- Java中的static和final作用
- ACL match-order 中的 config 与 auto 的应用区别
- PChart绘制连着Y轴的横线