C++ 图书管理系统:按出版日期排序的图书数据结构
#include
struct Book { string name; string author; string date; };
bool cmp(const Book &a, const Book &b) { return a.date < b.date; }
int main() { int n; cin >> n; Book *books = new Book[n]; for(int i = 0; i < n; i++) { cin >> books[i].name >> books[i].author >> books[i].date; } sort(books, books+n, cmp); for(int i = 0; i < n; i++) { cout << books[i].name << ' ' << books[i].author << ' ' << books[i].date << endl; } delete[] books; return 0; }
原文地址: http://www.cveoy.top/t/topic/ojIY 著作权归作者所有。请勿转载和采集!