這個題就是單純的結構體排序問題,有一個小問題就是,冒泡排序是穩定排序,是不會打亂相同大小數字的順序的,快速排序會打亂順序。
注意使用冒泡排序。
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 1005;
struct node {
string name;
string sex;
int age;
int score;
}st[MAXN];
int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++)
cin >> st[i].name >> st[i].sex >> st[i].age >> st[i].score;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n - i - 1; j++) {
if(st[j].score > st[j+1].score) {
swap(st[j], st[j+1]);
}
}
}
for(int i = 0; i < n; i++)
cout << st[i].name << " " << st[i].sex << " " << st[i].age << " " << st[i].score << endl;
return 0;
}