Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
436435 方相宜 【C5-9】合影效果 C++ 通过 100 2 MS 260 KB 1376 2026-04-14 19:27:19

Tests(10/10):


#include <iostream> #include <vector> #include <algorithm> #include <iomanip> // 用于控制输出格式 using namespace std; struct Person { string gender; float height; }; bool compareMale(const Person& a, const Person& b) { return a.height < b.height; // 男生按身高升序 } bool compareFemale(const Person& a, const Person& b) { return a.height > b.height; // 女生按身高降序 } int main() { int n; cin >> n; vector<Person> males, females; for (int i = 0; i < n; ++i) { Person p; cin >> p.gender >> p.height; if (p.gender == "male") { males.push_back(p); } else { females.push_back(p); } } // 排序男生和女生 sort(males.begin(), males.end(), compareMale); sort(females.begin(), females.end(), compareFemale); // 合并结果 vector<float> result; for (const auto& male : males) { result.push_back(male.height); } for (const auto& female : females) { result.push_back(female.height); } // 输出结果,保留两位小数 for (int i = 0; i < result.size(); ++i) { if (i > 0) { cout << " "; } cout << fixed << setprecision(2) << result[i]; } cout << endl; return 0; }


测评信息: