文章

4

粉丝

223

获赞

4

访问

18.1k

头像
这题意思难懂,而且陷阱多
P1310 浙江大学机试题
发布于2022年8月11日 16:29
阅读数 4.5k

定义五种排序方式,具体细节可见代码,需要注意一点:

每次排序之后进行排名时需要对照相邻元素是否相等,如果相等排名可能会一样

#include <bits/stdc++.h>
using namespace std;

struct Country {
    int no, gold, medal, population;
    double gold_scale, medal_scale;
    int rank[4];
};

bool cmp1(Country a, Country b) {
    return a.gold > b.gold;
}

bool cmp2(Country a, Country b) {
    return a.medal > b.medal;
}

bool cmp3(Country a, Country b) {
    return a.gold_scale > b.gold_scale;
}

bool cmp4(Country a, Country b) {
    return a.medal_scale > b.medal_scale;
}

bool cmp5(Country a, Country b) {
    return a.no < b.no;
}

int main() {
    int N, M;
    
    while(cin >> N >> M) {
        struct Country* country = new struct Country[N];
        struct...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发