#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Book
{
string Author;
unsigned short PublicationYear;
bool operator==(const Book& struc) const
{
return
Author == struc.Author &&
PublicationYear == struc.PublicationYear;
}
Book(string author, unsigned short publicationYear) :
Author(author),
PublicationYear(publicationYear)
{
}
};
int main()
{
vector<Book> books =
{
Book("Pushkin", 1831),
Book("Blok", 1902),
Book("Yevtushenko", 1962)
};
cout << "Sorting by name" << endl;
sort(books.begin(), books.end(), [](const Book& a, const Book& b) {
return a.Author < b.Author;
});
for (auto& book : books)
cout << "Author: " << book.Author << ", Year: " << book.PublicationYear << endl;
cout << "Sorting by year" << endl;
sort(books.begin(), books.end(), [](const Book& a, const Book& b) {
return a.PublicationYear < b.PublicationYear;
});
for (auto& book : books)
cout << "Author: " << book.Author << ", Year: " << book.PublicationYear << endl;
return 0;
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBCb29rCnsKICAgIHN0cmluZyBBdXRob3I7CiAgICB1bnNpZ25lZCBzaG9ydCBQdWJsaWNhdGlvblllYXI7CgogICAgYm9vbCBvcGVyYXRvcj09KGNvbnN0IEJvb2smIHN0cnVjKSBjb25zdAogICAgewogICAgICAgIHJldHVybgogICAgICAgICAgICBBdXRob3IgPT0gc3RydWMuQXV0aG9yICYmCiAgICAgICAgICAgIFB1YmxpY2F0aW9uWWVhciA9PSBzdHJ1Yy5QdWJsaWNhdGlvblllYXI7CiAgICB9CiAgICAKICAgIEJvb2soc3RyaW5nIGF1dGhvciwgdW5zaWduZWQgc2hvcnQgcHVibGljYXRpb25ZZWFyKSA6CiAgICAgICAgQXV0aG9yKGF1dGhvciksCiAgICAgICAgUHVibGljYXRpb25ZZWFyKHB1YmxpY2F0aW9uWWVhcikKICAgIHsKICAgIH0KfTsKCmludCBtYWluKCkKewogICAgdmVjdG9yPEJvb2s+IGJvb2tzID0KICAgIHsKICAgICAgICBCb29rKCJQdXNoa2luIiwgMTgzMSksCiAgICAgICAgQm9vaygiQmxvayIsIDE5MDIpLAogICAgICAgIEJvb2soIllldnR1c2hlbmtvIiwgMTk2MikKICAgIH07CiAgICAKICAgIGNvdXQgPDwgIlNvcnRpbmcgYnkgbmFtZSIgPDwgZW5kbDsKICAgIHNvcnQoYm9va3MuYmVnaW4oKSwgYm9va3MuZW5kKCksIFtdKGNvbnN0IEJvb2smIGEsIGNvbnN0IEJvb2smIGIpIHsKICAgICAgICByZXR1cm4gYS5BdXRob3IgPCBiLkF1dGhvcjsKICAgIH0pOwogICAgCiAgICBmb3IgKGF1dG8mIGJvb2sgOiBib29rcykKICAgICAgICBjb3V0IDw8ICJBdXRob3I6ICIgPDwgYm9vay5BdXRob3IgPDwgIiwgWWVhcjogIiA8PCBib29rLlB1YmxpY2F0aW9uWWVhciA8PCBlbmRsOwogICAgCiAgICBjb3V0IDw8ICJTb3J0aW5nIGJ5IHllYXIiIDw8IGVuZGw7CiAgICBzb3J0KGJvb2tzLmJlZ2luKCksIGJvb2tzLmVuZCgpLCBbXShjb25zdCBCb29rJiBhLCBjb25zdCBCb29rJiBiKSB7CiAgICAgICAgcmV0dXJuIGEuUHVibGljYXRpb25ZZWFyIDwgYi5QdWJsaWNhdGlvblllYXI7CiAgICB9KTsKICAgIAogICAgZm9yIChhdXRvJiBib29rIDogYm9va3MpCiAgICAgICAgY291dCA8PCAiQXV0aG9yOiAiIDw8IGJvb2suQXV0aG9yIDw8ICIsIFllYXI6ICIgPDwgYm9vay5QdWJsaWNhdGlvblllYXIgPDwgZW5kbDsKCiAgICByZXR1cm4gMDsKfQ==