修复了?
This commit is contained in:
+6
-9
@@ -10,11 +10,11 @@ typedef struct {
|
|||||||
} book;
|
} book;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
book books[];
|
book *books;
|
||||||
int number_of_books;
|
int number_of_books;
|
||||||
} book_and_number;
|
} book_and_number;
|
||||||
|
|
||||||
double max_price(book *books, int n) {
|
double find_max_price(book *books, int n) {
|
||||||
double max_price = 0;
|
double max_price = 0;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
if (books[i].price > max_price) {
|
if (books[i].price > max_price) {
|
||||||
@@ -25,19 +25,16 @@ double max_price(book *books, int n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
book_and_number max_price_books(book *books, int n) {
|
book_and_number max_price_books(book *books, int n) {
|
||||||
double max_price = max_price(books, n);
|
double max_price = find_max_price(books, n);
|
||||||
|
|
||||||
book_and_number books_and_number;
|
book_and_number books_and_number;
|
||||||
book max_price_books[];
|
|
||||||
|
|
||||||
books_and_number.number_of_books = 0;
|
books_and_number.number_of_books = 0;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
if (books[i].price == max_price) {
|
if (books[i].price == max_price) {
|
||||||
max_price_books[i] = books[i];
|
books_and_number.books[i] = books[i];
|
||||||
books_and_number.number_of_books++;
|
books_and_number.number_of_books++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
books_and_number.books = &max_price_books;
|
|
||||||
return books_and_number;
|
return books_and_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +58,7 @@ int main() {
|
|||||||
int n;
|
int n;
|
||||||
cin >> n;
|
cin >> n;
|
||||||
input(books, n);
|
input(books, n);
|
||||||
max_price(books, n);
|
find_max_price(books, n);
|
||||||
book_and_number books_and_number = max_price_books(books, n);
|
book_and_number books_and_number = max_price_books(books, n);
|
||||||
output(books_and_number);
|
output(books_and_number);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user