Run ID:73517

提交时间:2024-05-19 11:57:15

#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Book { int id; string name; int quantity; int totalPrice; double unitPrice; }; bool compareByUnitPrice(const Book& a, const Book& b) { return a.unitPrice > b.unitPrice; } int main() { int n; cin >> n; vector<Book> books(n); for (int i = 0; i < n; ++i) { cin >> books[i].id >> books[i].name >> books[i].quantity >> books[i].totalPrice; books[i].unitPrice = static_cast<double>(books[i].totalPrice) / books[i].quantity; } sort(books.begin(), books.end(), compareByUnitPrice); cout << books[0].id << " " << books[0].name << " " << books[0].quantity << " " << books[0].totalPrice << " " << books[0].unitPrice << endl; return 0; }