cpp实现:
#include<iostream>
using namespace std;
#include<string>
#include<vector>
#include<iomanip>
struct Book
{
string name;
float price;
int classification;
}book[101];
int main(){
int n;
scanf("%d",&n);
for (int i=0; i<n; i++){
cin>>book[i].name>>book[i].price>>book[i].classification;
}
// 冒泡排序
for (int i=0; i<n-1; i++){
int index = i;
for (int j=i+1; j<n; j++){
if (book[index].price>book[j].price){
index = j;
}else if (book[index].price==book[j].price && (book[index].name>book[j].name)){
// cout<<book[index].name<<", "<<book[j].name<<endl;
index = j;
}
// else{
// cout<<book[index].name<<", "<<book[j].name<<endl;
// cout<<(book[index].name>book[j].name)<<endl;
// }
}
if (index!=i){
Book tmp = book[i];
book[i] = book[index];
book[index] = tmp;
}
}
// cout<<endl;
for (int i=0; i<n; i++){
cout<<book[i].name<<","<<fixed<<setprecision(2)<<book[i].price<<","<<book[i].classification
<<endl;
}
return 0;
}