73 lines
1.9 KiB
C++
73 lines
1.9 KiB
C++
#include <iostream>
|
|
#include <iomanip>
|
|
|
|
using namespace std;
|
|
|
|
typedef struct {
|
|
string id;
|
|
string name;
|
|
double price;
|
|
} book;
|
|
|
|
typedef struct {
|
|
book *books;
|
|
int number_of_books;
|
|
} book_and_number;
|
|
|
|
double find_max_price(book *books, int n) {
|
|
double max_price = 0;
|
|
for (int i = 0; i < n; i++) {
|
|
if (books[i].price > max_price) {
|
|
max_price = books[i].price;
|
|
}
|
|
}
|
|
return max_price;
|
|
}
|
|
|
|
book_and_number max_price_books(book *books, int n) {
|
|
double max_price = find_max_price(books, n);
|
|
book_and_number books_and_number;
|
|
books_and_number.books = new book[100];
|
|
books_and_number.number_of_books = 0;
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
if (books[i].price == max_price) {
|
|
books_and_number.books[i].id = books[i].id;
|
|
books_and_number.books[i].name = books[i].name;
|
|
books_and_number.books[i].price = books[i].price;
|
|
books_and_number.number_of_books++;
|
|
}
|
|
}
|
|
return books_and_number;
|
|
}
|
|
|
|
void input(book *books, int n) {
|
|
for (int i = 0; i < n; i++) {
|
|
cin >> books[i].id >> books[i].name >> books[i].price;
|
|
}
|
|
}
|
|
|
|
void output(book_and_number *books_and_number) {
|
|
cout << books_and_number->number_of_books << endl;
|
|
for (int i = 0; true; i++) {
|
|
if (books_and_number->books[i].price != 0) {
|
|
for (int j = 1; j < i + books_and_number->number_of_books; j++) {
|
|
cout << books_and_number->books[i].id << " " << books_and_number->books[i].name << " " << fixed <<
|
|
setprecision(2) << books_and_number->books[i].price << endl;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
book books[100];
|
|
int n;
|
|
cin >> n;
|
|
input(books, n);
|
|
find_max_price(books, n);
|
|
book_and_number books_and_number = max_price_books(books, n);
|
|
output(&books_and_number);
|
|
return 0;
|
|
}
|