Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <tuple>
- struct Book {
- std::string name;
- std::string publisher;
- std::int32_t price;
- Book(const std::string& name, const std::string& publisher, std::int32_t price)
- : name(name), publisher(publisher), price(price) {}
- };
- bool operator<(const Book&a, const Book& b) {
- return std::tie(a.name, a.publisher, a.price) < std::tie(b.name, b.publisher, b.price);
- }
- int main()
- {
- std::vector<Book> books = {
- {"ポケットプログレッシブ英和辞典〔第3版〕","小学館", 1750},
- {"スクリプト言語による効率的ゲーム開発", "ソフトバンククリエイティブ",3800}
- };
- std::sort(books.begin(), books.end());
- for(const Book& book: books) {
- std::cout << book.name << "[" << book.publisher << "]" << book.price << "円" << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement