题解 | #牛牛的书#
牛牛的书
https://www.nowcoder.com/practice/30bb969e117b4f6d934d4b60a2af7489
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; class Book{ public: Book(string name,int price) { this->m_name=name; this->m_price=price; } void print() { cout<<m_name<<endl; } string m_name; int m_price; }; bool Myconpare(Book &b1,Book &b2) { return b1.m_price<b2.m_price; } int main() { vector<Book> v; int n; cin>>n; for(int i=0;i<n;i++) { string name; int price; cin>>name>>price; Book b(name,price); v.push_back(b); } sort(v.begin(),v.end(),Myconpare); for(vector<Book>::iterator it=v.begin();it!=v.end();it++) { (*it).print(); } return 0; } // 64 位输出请用 printf("%lld")