ZOJ 2727 List the Books
2013-03-08 15:40
309 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1727
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; struct Book { string Name; int Year; int Price; }; bool CompName(const Book &b1,const Book &b2) { if(b1.Name!=b2.Name) return b1.Name<b2.Name; else if(b1.Year!=b2.Year) return b1.Year<b2.Year; else if(b1.Price!=b2.Price) return b1.Price<b2.Price; } bool CompYear(const Book &b1,const Book &b2) { if(b1.Year!=b2.Year) return b1.Year<b2.Year; else if(b1.Name!=b2.Name) return b1.Name<b2.Name; else if(b1.Price!=b2.Price) return b1.Price<b2.Price; } bool CompPrice(const Book &b1,const Book &b2) { if(b1.Price!=b2.Price) return b1.Price<b2.Price; else if(b1.Name!=b2.Name) return b1.Name<b2.Name; else if(b1.Year!=b2.Year) return b1.Year<b2.Year; } int main() { vector<Book>v; Book book; string sorting; int line=0; int n; while(cin>>n&&n) { line++; v.clear(); for(int i=0;i<n;i++) { cin>>book.Name>>book.Year>>book.Price; v.push_back(book); } cin>>sorting; if(sorting=="Name") sort(v.begin(),v.end(),CompName); if(sorting=="Year") sort(v.begin(),v.end(),CompYear); if(sorting=="Price") sort(v.begin(),v.end(),CompPrice); if(line!=1) cout<<endl; for(int i=0;i<v.size();i++) cout<<v[i].Name<<" "<<v[i].Year<<" "<<v[i].Price<<endl; } return 0; }
相关文章推荐
- zoj 2727 List the Books(排序)
- zoj 2727 List the Books(三级排序 = =水题)
- zoj 2727 List the Books
- zoj 2727 list the books
- zoj 2727 List the Book
- ZOJ List the Books 水~
- ZOJ List the Books 水~
- Question[SQL]: How can I list all book with prices greather than the average price of books of the same type?
- List the Books(sort)
- ZOJ2727 List the Books
- 转载:The Essential List of JavaScript, jQuery, HTML & CSS Books to Make You a Better Web Developer
- A list of books on general-purpose algorithms for the practical programmer (or 'software engineer')
- ZOJ-2770 Burn the Linked Camp 差分约束
- ZOJ 题目1610 Count the Colors(线段树求颜色及有多少段)
- ZOJ 2770 Burn the Linked Camp 差分约束 ZOJ排名第一~
- zoj -- 3885 The Exchange of Items(最小费用最大流)
- ZOJ 2787 Children of the Candy Corn
- 用PowerDesigner逆向数据库工程时”Unable to list the table"错误的解决方法(转载)
- Overcoming the List View Threshold in SharePoint CAML queries
- BestCoder Round #59 Reorder the Books