ZOJ 2727List the Books

2014-11-24 11:43:33 · 作者: · 浏览: 0
[cpp]
#include
#include
#include
#include
#include
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 else if(b1.Year!=b2.Year)
return b1.Year else
return b1.Price }
bool CompYear(const Book &b1,const Book &b2)
{
if(b1.Year!=b2.Year)
return b1.Year else if(b1.Name!=b2.Name)
return b1.Name else
return b1.Price }
bool CompPrice(const Book &b1,const Book &b2)
{
if(b1.Price!=b2.Price)
return b1.Price else if(b1.Name!=b2.Name)
return b1.Name else
return b1.Year
}
int main()
{
//ifstream cin("acmilan.txt");
vector v;
Book book;
string sorting;
int n;
int i;
int line=0;
while(cin>>n)
{
if(n==0)
break;
line++;
v.clear();
for(i=0;i {
cin>>book.Name>>book.Year>>book.Price;
v.push_back(book);
}
cin>>sorting;
if(sorting=="Name")
sort(v.begin(),v.end(),CompName);
else if(sorting=="Year")
sort(v.begin(),v.end(),CompYear);
else if(sorting=="Price")
sort(v.begin(),v.end(),CompPrice);
if(line!=1)
cout< for(i=0;i {
cout< }

}
//system("pause");
return 0;
}
作者:teibin