You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
788 B

#include <bits/stdc++.h>
using namespace std;
int main() {
vector<float> v1;
vector<float> v2;
int n;
string sex;
float h;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> sex >> h;
if (sex == "male") {
v1.push_back(h);
} else {
v2.push_back(h);
}
}
//男生从小到大
sort(v1.begin(), v1.end(), less<float>());
//女生从大到小
sort(v2.begin(), v2.end(), greater<float>());
// 输出
for (int i = 0; i < v1.size(); ++i) {
cout << fixed << setprecision(2) << v1[i] << " "; //注意保留两位小数
}
for (int i = 0; i < v2.size(); ++i) {
cout << fixed << setprecision(2) << v2[i] << " ";
}
return 0;
}