Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
73517 | 刘浩宇 | 单价最高的书 | C++ | Accepted | 1 MS | 272 KB | 820 | 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; }