用c语言给我写
时间: 2024-02-13 20:07:37 浏览: 59
好的,以下是用 C 语言实现的代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Book {
char name[101];
char author[101];
char date[11];
};
int cmp(const void* a, const void* b) {
struct Book* bookA = (struct Book*) a;
struct Book* bookB = (struct Book*) b;
return strcmp(bookA->date, bookB->date);
}
int main() {
int n;
scanf("%d", &n);
struct Book books[n];
for(int i = 0; i < n; i++) {
scanf("%s %s %s", books[i].name, books[i].author, books[i].date);
}
qsort(books, n, sizeof(struct Book), cmp);
for(int i = 0; i < n; i++) {
printf("%s %s %s\n", books[i].name, books[i].author, books[i].date);
}
return 0;
}
```
希望能够帮助到你!
相关推荐
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)