p1093错哪了?

P1093 [NOIP2007 普及组] 奖学金

SDXpanyang @ 2024-12-29 20:09:32

    • [ ] # 怎么做?
include<bits/stdc++.h>
using namespace std;
int n;
typedef struct jxj{
    int xh;
    int yu;
    int shu;
    int ying;
    int zong;
}jxj;
jxj xj[310];
bool cmp(jxj a,jxj b){
    if(a.zong>b.zong)return 1;
    if(a.zong==b.zong&&a.yu>b.yu)return 1;
    if(a.xh<b.xh&&a.zong==b.zong)return 1;
    return 0;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        xj[i].xh=i;
        cin>>xj[i].yu>>xj[i].shu>>xj[i].ying;
        xj[i].zong=xj[i].yu+xj[i].shu+xj[i].ying;
    }
    sort(xj+1,xj+n+1,cmp);
    for(int i=1;i<=5;i++)cout<<xj[i].xh<<' '<<xj[i].zong<<'\n';
    return 0;
}

大家,哪里错了?


by jingliang_youxi @ 2024-12-29 20:13:55

我的cmp是这样

bool cmp(stu x, stu y) {
    if (x.ans != y.ans)
        return x.ans > y.ans;
    if (x.yw != y.yw)
        return x.yw > y.yw;

    return x.id < y.id;
}

by dalu @ 2024-12-29 20:15:22

@SDXpanyang

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

class stu{
public:
    int num,score;
    int Ch,En,ma;
    friend bool operator > (stu a,stu b){
        if(a.score > b.score) return true;
        else if(a.score < b.score) return false;
        else{
            if(a.Ch > b.Ch) return true;
            else if(a.Ch < b.Ch) return false;
            else{
                if(a.num > b.num) return false;
                else return true;
            }
        }
    }
}a[310];

int main(){
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++){
        a[i].num = i;
        cin >> a[i].Ch >> a[i].ma >> a[i].En;
        a[i].score = a[i].Ch + a[i].ma + a[i].En;
    }
    sort(a + 1,a + n + 1,greater < stu >());
    for(int i = 1;i <= 5;i++)
        cout << a[i].num << ' ' << a[i].score << '\n';
    return 0;
}

by SDXpanyang @ 2024-12-29 20:52:53

谢谢大家!


by SDXpanyang @ 2024-12-29 20:59:48

我非常感谢!


|