文章

24

粉丝

0

获赞

180

访问

4.1k

头像
成绩排序 - 西电 题解:自定义sort的排序规则
P1733 西安电子科技大学机试题
发布于2026年2月13日 10:18
阅读数 192

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct G {
    int year;
    int month;
    int day;
    int grade;
};

bool des_grade(G g1, G g2) {
    return g1.grade > g2.grade;    
}

bool asc_day(G g1, G g2) {
    return g1.day < g2.day;    
}

bool asc_month(G g1, G g2) {
    return g1.month < g2.month;    
}

bool asc_year(G g1, G g2) {
    return g1.year < g2.year;    
}

int main() {
    int n;
    while(cin >> n) {
        vector<G> v(n);
        for(int i = 0; i < n; i++)
            scanf("%d/%d/%d %d",&v[i].year,&v[i].month,&v[i].day,&v[i].grade);
        stable_sort(v.begin(),v.end(),asc_day);
        stable_sort(v.begin(),v.end(),asc_month);
        stable_sort(v.begin(),v.end(),asc_year);
        stable_sort(v.begin(),v.end(),des_grade);
        for(auto ele : v) 
            printf("%...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发