以下是使用 C++ 解决此问题的代码: ```cpp #include <iostream> #include <vector> #include <algorithm> struct Athlete { int id; double score; }; bool compareAthletes(Athlete a, Athlete b) { return a.score < b.score; } int main() { std::vector<Athlete> athletes = { {1, 13.6}, {2, 14.8}, {10, 12.0}, {11, 12.7}, {23, 15.6}, {25, 13.4}, {31, 14.9}, {36, 12.6}, {37, 13.4}, {102, 12.5} }; std::sort(athletes.begin(), athletes.end(), compareAthletes); for (int i = 0; i < athletes.size(); i++) { std::cout << i + 1 << " " << athletes[i].id << " " << athletes[i].score << std::endl; } return 0; } ``` 这段代码首先定义了一个结构体来存储运动员的编号和成绩。然后使用自定义的比较函数对运动员成绩进行排序,最后输出排序后的名次、运动员号和成绩。 [2024-11-16 21:16:59 | AI写代码神器 | 334点数解答]