#include #include #include #include

using namespace std;

struct Person { string gender; float height; };

bool compareHeight(const Person& p1, const Person& p2) { if (p1.gender == 'male' && p2.gender == 'female') { return true; } else if (p1.gender == 'female' && p2.gender == 'male') { return false; } else { if (p1.gender == 'male') { return p1.height < p2.height; } else { return p1.height > p2.height; } } }

int main() { int n; cin >> n;

vector<Person> people(n);
for (int i = 0; i < n; i++) {
    cin >> people[i].gender >> people[i].height;
}

sort(people.begin(), people.end(), compareHeight);

for (int i = 0; i < n; i++) {
    cout << fixed << setprecision(2) << people[i].height << ' ';
}

return 0;

}

C++ 香山合影 排队算法:男生升序,女生降序

原文地址: https://www.cveoy.top/t/topic/i8QL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录