文章

85

粉丝

0

获赞

391

访问

7.7k

头像
成绩排序2.0 题解:
P1159 清华大学上机题
发布于2026年3月4日 15:44
阅读数 67

#include <bits/stdc++.h>
using namespace std;
struct student {
    int id;
    int score;
}s;

bool cmp(student a, student b) {
    if (a.score < b.score) return true;
    if (a.score ==b.score) {
        if (a.id < b.id) return true;
        else return false;
    }
    return false;
}
int main() {
    int n;
    cin>>n;
    vector<student> v;
    for (int i=0;i<n;i++) {
        int id;
        cin>>id;
        int score;
        cin>>score;
        student student;
        student.id = id;
        student.score = score;
        v.push_back(student);
    }
    sort(v.begin(), v.end(), cmp);
    for (int i=0;i<v.size();i++) {
        cout<<v[i].id<<" "<<v[i].score<<endl;
    }

}
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发