6,7,8,10不过,求助

P1093 [NOIP2007 普及组] 奖学金

O_00_00 @ 2021-11-14 10:08:33

自定义结构体加手写快排,请dalao挑错

#include<iostream>

using namespace std;

struct Student{
    int ID,C,M,E,A;
};

void quicksort(Student a[],int l,int r){

    if(l >= r) return;
    int x = a[(l + r)/2].A;
    int i = l - 1,j = r + 1;
    while(i < j){
        do i++;while(a[i].A > x);
        do j--;while(a[j].A < x);
        if(i < j) swap(a[i],a[j]);
    }
    quicksort(a,l,j);
    quicksort(a,j+1,r);

}

int main(){

    int n;
    cin >> n;
    Student a[n + 1];
    for(int i = 1;i <= n;i++){
        cin >> a[i].C >> a[i].M >> a[i].E;
        a[i].A = a[i].C + a[i].M + a[i].E;
        a[i].ID = i;
    }
    quicksort(a,1,n);
    for(int i = 1;i <= 5;i++){
        cout << a[i].ID << " " << a[i].A << endl;
    }

    return 0;
}
来自三个月的蒟蒻的求助

|