Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
73513 刘浩宇 单价最高的书 C++ Wrong Answer 1 MS 276 KB 965 2024-05-19 11:56:07

Tests(0/2):


Code:

#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 << "最高单价的书的编号、书名、数量,总价,单价:" << endl; cout << books[0].id << " " << books[0].name << " " << books[0].quantity << " " << books[0].totalPrice << " " << books[0].unitPrice << endl; return 0; }


Run Info:

------Input------
3 1 Cinderella 12 120 2 Hoodwinked 10 150 3 Thumbelina 15 120
------Answer-----
2 Hoodwinked 10 150 15
------Your output-----
最高单价的书的编号、书名、数量,总价,单价: 2 Hoodwinked 10 150 15