90分求调

P1093 [NOIP2007 普及组] 奖学金

beimingyouniu @ 2024-07-31 09:42:03

90分,#8没过


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

int n;

struct data {
    int yw, sx, yy;
    int zongfen;
    int xuehao;
} a[301];

bool cmp(data a, data b) {
    if (a.zongfen > b.zongfen)
        return 1;
    else if (a.zongfen < b.zongfen)
        return 0;
    else {
        if (a.yw > b.yw)
            return 1;
        else if (a.yw < b.yw)
            return 0;
        else {
            if (a.xuehao > b.xuehao)
                return 1;
            else if (a.xuehao < b.xuehao)
                return 0;
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d%d", &a[i].yw, &a[i].sx, &a[i].yy);
        a[i].zongfen = a[i].yw + a[i].sx + a[i].yy;
        a[i].xuehao = i;
    }
    sort(a + 1, a + n + 1, cmp);
    for (int i = 1; i <= 5; i++)
        printf("%d %d\n", a[i].xuehao, a[i].zongfen);
    return 0;
}

by FJ_00460 @ 2024-07-31 09:50:50

这个cmp可以简化


by FJ_00460 @ 2024-07-31 09:51:39

可以在函数最底写一个return 0


by FJ_00460 @ 2024-07-31 09:52:02

就会更清晰


by FJ_00460 @ 2024-07-31 09:52:47

或者像这样

bool cmp(money a, money b)
{
    if(a.zong != b.zong)return a.zong > b.zong;
    if(a.chinese != b.chinese)return a.chinese > b.chinese;
    return a.ide < b.ide;
}

by FJ_00460 @ 2024-07-31 09:53:44

问题出在i < 5


by FJ_00460 @ 2024-07-31 09:54:32

好像不对


by FJ_00460 @ 2024-07-31 09:56:30

我写的是<5

记录

90分


by FJ_00460 @ 2024-07-31 09:57:20

不对,你cmp错了,id是<为1>为0


by beimingyouniu @ 2024-07-31 10:10:53

@water8424 谢谢 已AC 已关


|