题解 | #牛牛的书#
牛牛的书
https://www.nowcoder.com/practice/30bb969e117b4f6d934d4b60a2af7489
#include <iostream> #include<string> #include<vector> #include<algorithm> using namespace std; struct Book{ string name; int price; }; bool comparePrice(const Book &b1,const Book &b2) { return b1.price<b2.price; } int main() { int n; cin>>n; vector<Book> books(n); for(int i=0;i<n;i++) { cin >>books[i].name>>books[i].price; } sort(books.begin(),books.end(),comparePrice); for(const auto &book:books) { cout <<book.name<<endl; } return 0; }