萌新求助!!! sort报错

P5740 【深基7.例9】最厉害的学生

_Creeper_ @ 2024-01-26 21:45:13

报错代码

requset for member 'sumn' in 'stu',which is none class type 'node[1005]'

code:

#include<bits/stdc++.h>
using namespace std;
struct node
{
    string s;
    int a,b,c,sumn,id;
};
node stu[1005];
bool cmp(node x,node y)
{
    if(x.sumn==y.sumn) return x.id<y.id;
    return x.sumn>y.sumn;
}
int main()
{ 
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>stu[i].s>>stu[i].a>>stu[i].b>>stu[i].c;
        stu[i].sumn=stu[i].a+stu[i].b+stu[i].c;
        stu[i].id=i;
    }
    sort(stu.sumn,stu.sumn+n,cmp);//不知道哪里有问题
    cout<<stu[0].s;
}

求大佬解决!!!


by _up111 @ 2024-01-26 21:58:25

sort的用法自己查一下


by _Creeper_ @ 2024-01-26 22:00:45

谢了


上一页 |