1 条题解
-
1
#include <bits/stdc++.h> using namespace std; struct Stu { string gender; //性别 double height; //身高 }; int n; Stu a[45]; //自定义排序规则 bool cmp(Stu x, Stu y) { if (x.gender != y.gender) return x.gender == "male" && y.gender == "female"; if (x.gender == "male") return x.height < y.height; return x.height > y.height; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].gender >> a[i].height; sort(a + 1, a + n + 1, cmp); for (int i = 1; i <= n; i++) cout << fixed << setprecision(2) << a[i].height << " "; return 0; }
- 1
信息
- ID
- 402
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 2
- 标签
- (无)
- 递交数
- 54
- 已通过
- 35
- 上传者