#include <stdio.h> #include <stdlib.h> #include <string.h>

typedef struct { char title[101]; char author[101]; char date[11]; } Book;

int compare(const void *a, const void *b) { Book *bookA = (Book *)a; Book *bookB = (Book *)b; return strcmp(bookA->date, bookB->date); }

int main() { int n; scanf('%d', &n); Book *books = (Book *)malloc(n * sizeof(Book)); for (int i = 0; i < n; i++) { scanf('%s %s %s', books[i].title, books[i].author, books[i].date); } qsort(books, n, sizeof(Book), compare); for (int i = 0; i < n; i++) { printf('%s %s %s ', books[i].title, books[i].author, books[i].date); } free(books); return 0; }

C语言实现图书管理系统:按出版日期排序图书信息

原文地址: https://www.cveoy.top/t/topic/ojJS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录