设你正在开发一个图书管理系统你需要设计一个数指结构来表示图书。每本书包书名、作和出版日明。按出版日丹序排序即先出版的图书排右前面输入:从键盘输入个整数1==100表示图书数量然后输入n行每行包含一本图书5的息书名不概时100个字符、作名不超过100个宁符和出版日明格式为YYYY MM-DD】数据之间用空格开输出:按排序后的序输出的信息每本图书行包护书名、作考和出饭日明数据之间用空格隔开CC+
#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;
原文地址: https://cveoy.top/t/topic/fDBR 著作权归作者所有。请勿转载和采集!