Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
319694 王栎州 【C5-9】合影效果 C++ 通过 100 1 MS 276 KB 1809 2025-04-29 17:56:15

Tests(10/10):


#include <iostream> #include <iomanip> using namespace std; struct Person { string gender; double height; }; void bubbleSortAsc(Person arr[], int size) { for (int i = 0; i < size - 1; i++) { for (int j = 0; j < size - i - 1; j++) { if (arr[j].height > arr[j + 1].height) { Person temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } } // 冒泡排序降序 void bubbleSortDesc(Person arr[], int size) { for (int i = 0; i < size - 1; i++) { for (int j = 0; j < size - i - 1; j++) { if (arr[j].height < arr[j + 1].height) { // 交换元素 Person temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } } int main() { int n; cin >> n; Person people[100]; Person males[100], females[100]; int maleIndex = 0, femaleIndex = 0; // 输入数据并分类 for (int i = 0; i < n; i++) { cin >> people[i].gender >> people[i].height; if (people[i].gender == "male") { males[maleIndex++] = people[i]; } else { females[femaleIndex++] = people[i]; } } bubbleSortAsc(males, maleIndex); bubbleSortDesc(females, femaleIndex); // 输出结果 cout << fixed << setprecision(2); for (int i = 0; i < maleIndex; i++) { cout << males[i].height << " "; } for (int i = 0; i < femaleIndex; i++) { cout << females[i].height; if (i != femaleIndex - 1) { cout << " "; } } cout << endl; return 0; }


测评信息: