题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
#include <iostream>
#include <map>
using namespace std;
//这里使用mutilmap里的自动排序,将成绩和姓名进行调换,将成绩作为key进行排序
//如果==0就用降序 ==1用升序
int main() {
int n, comp;
while (cin >> n) {
cin >> comp;
if (comp == 0) {
multimap<int, string, greater<int>> m1;
for (int i = 0; i < n; i++) {
string s;
int k;
cin >> s;
cin >> k;
m1.emplace(k, s);
}
for(auto e :m1)
{
cout<<e.second<<" "<<e.first<<endl;
}
} else if (comp == 1) {
multimap<int, string> m1;
for (int i = 0; i < n; i++) {
string s;
int k;
cin >> s;
cin >> k;
m1.emplace(k, s);
}
for(auto e :m1)
{
cout<<e.second<<" "<<e.first<<endl;
}
}
}
}
// 64 位输出请用 printf("%lld")

