#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
struct Book{
string book;
int year;
int price;
};
bool NameSort(const Book &s1, const Book &s2)
{
if (s1.book != s2.book) return s1.book < s2.book;
else if (s1.year != s2.year) return s1.year < s2.year;
else return s1.price < s2.price;
}
bool YearSort(const Book &s1, const Book &s2)
{
if (s1.year != s2.year) return s1.year < s2.year;
else if (s1.book != s2.book) return s1.book < s2.book;
else return s1.price < s2.price;
}
bool PriceSort(const Book &s1, const Book &s2)
{
if (s1.price != s2.price) return s1.price < s2.price;
else if (s1.book != s2.book) return s1.book < s2.book;
else return s1.year < s2.year;
}
int main()
{
ifstream cin("2727.txt");
int n;
string SortWay;
Book book;
vector<Book> v;
while (cin >> n && n)
{
v.clear();
for (int i = 0; i < n; ++i)
{
cin >> book.book >> book.year >> book.price;
v.push_back(book);
}
cin >> SortWay;
if (SortWay == "Name")
{
sort(v.begin(), v.end(), NameSort);
}
else if (SortWay == "Year")
{
sort(v.begin(), v.end(), YearSort);
}
else if (SortWay == "Price")
{
sort(v.begin(), v.end(), PriceSort);
}
for (auto it = v.begin(); it != v.end(); ++it)
{
cout << (*it).book << " " << (*it).year << " " << (*it).price << endl;
}
cout << endl;
}
return 0;
}
zju2727
最新推荐文章于 2024-08-18 19:10:16 发布