萌新求助!!! 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 cff_0102 @ 2024-01-26 21:46:47

sort(stu.sumn,stu.sumn+n,cmp);

你在干啥


by _Creeper_ @ 2024-01-26 21:47:33

e? 排序stu里的sumn


by _up111 @ 2024-01-26 21:50:32

。。。。。应该是sort(stu,stu + n, cmp);


by _up111 @ 2024-01-26 21:51:07

麻烦你学好一点


by _Creeper_ @ 2024-01-26 21:51:39

怎么个理解法a


by lpk1118 @ 2024-01-26 21:51:49

sort(stu,stu+n,cmp);


by _Creeper_ @ 2024-01-26 21:52:12

对了 但不懂为啥


by _Creeper_ @ 2024-01-26 21:53:53

难道不用单独排序其中的数据吗 我看了下zhzzhzzzz大佬的题解


by _up111 @ 2024-01-26 21:57:11

你不是都写cmp了吗 @Creeper


by _Creeper_ @ 2024-01-26 21:58:20

如果不用cmp的话是不是可以用原来的写法?


| 下一页