题解 | 体重排序
体重排序
https://www.nowcoder.com/practice/28a03ebdd3eb490dba057f7c15ae8610
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
while (cin >> n) { // 注意 while 处理多个 case
string name;
double weight;
multimap<string, double> m;
for (int i = 0; i < n; i++) {
cin >> name >> weight;
m.insert({name, weight});
}
vector<pair<string, double>> vec(m.begin(), m.end());
sort(vec.begin(), vec.end(), [](const pair<string, double>& a, const pair<string, double>& b) { if (a.second != b.second) {
return a.second < b.second;
} else {
return a.first < b.first;
}
});
for (pair<string, double> i: vec) {
cout << i.first << " ";
}
}
}
// 64 位输出请用 printf("%lld")
查看16道真题和解析