求大佬帮助,运行错误

P1093 [NOIP2007 普及组] 奖学金

Ousmane_Dembele @ 2017-08-10 19:37:26

#include <bits/stdc++.h>
using namespace std;
struct student{
    int xuehao;
    int yuwen;
    int sum;
    int shuxue;
    int yingyu;
}stu[304];
int cmp(int x,int y){
    if(stu[x].sum>stu[y].sum)
       return 1;
    if(stu[x].sum<stu[y].sum)
       return 0;
    if(stu[x].yuwen>stu[y].yuwen)
       return 1;
    if(stu[x].yuwen<stu[y].yuwen)
       return 0;
    if(stu[x].xuehao<stu[y].xuehao)
       return 1;
    if(stu[x].xuehao>stu[y].xuehao)
       return 0;
}
int main()
{
    int n,a,b,c,i;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>stu[i].yuwen>>stu[i].shuxue>>stu[i].yingyu;
        stu[i].sum=stu[i].yuwen+stu[i].shuxue+stu[i].yingyu;
        stu[i].xuehao=i;
    }
    sort(stu+1,stu+n+1,cmp);
    for(i=1;i<=5;i++)
        cout<<stu[i].xuehao<<" "<<stu[i].sum<<endl;
    return 0;
}

by xun薰 @ 2017-08-10 19:47:53

cmp函数里不行该是数组下标吧..参数类型应该是结构体..


|