题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
#include <bits/stdc++.h>
using namespace std;
struct node {
    string name;
    int score;
    int  cnt;
};
bool cmp0(const node& x, const node& y) {
    if (x.score != y.score)
        return x.score > y.score;
    else
        return x.cnt<y.cnt;
}
bool cmp1(const node& x, const node& y) {
    if (x.score != y.score)
        return x.score < y.score;
    else
         return x.cnt<y.cnt;
}
node stu[205];
int n,mode;
int main() {
    cin>>n>>mode;
    for(int i = 0 ; i < n ; i++)
    {
        cin>>stu[i].name>>stu[i].score;
        stu[i].cnt = i;
    }
    if(mode)
        sort(stu,stu+n,cmp1);
    else
     sort(stu,stu+n,cmp0);
    for(int i = 0 ; i < n ; i++)
        cout<<stu[i].name<<" "<<stu[i].score<<endl;
}
// 64 位输出请用 printf("%lld")
 投递宇宙厂等公司10个岗位
投递宇宙厂等公司10个岗位 联想公司福利 1496人发布
联想公司福利 1496人发布