为什么编译失败

P1093 [NOIP2007 普及组] 奖学金

lr0818 @ 2024-10-06 20:28:22

#include <bits/stdc++.h>
using namespace std;
struct s{
    int a,e;
    long long d;
};
bool cmp(s x, s y) {
    if (x.e!=y.e)   return x.e>y.e;
    if (x.a!=y.a)   return x.a>y.a;
    return x.d<x.d;
}
int main() {
    long long n,b,c;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin>>a[i].a>>b>>c;
        a[i].d=i;
        a[i].e=a[i].a+b+c;
    }
    sort(a+1,a+n+1,cmp);
    for (int i = 1; i <= 5; i++) {
        cout<<a[i].d<<" "<<a[i].e<< "\n";
    }
    return 0;
}

by Grammar__hbw @ 2024-10-06 20:29:50

@lr0818 数组a没定义,还有你cmp里面有个自比较


by lqy404 @ 2024-10-06 20:30:08

没有定义a啦


by xiaoke2021 @ 2024-10-06 20:30:21

a数组没定义 @Ir0818


by dgz61 @ 2024-10-06 20:30:22

你没有定义a数组!!!(你怎么能犯这种错误


by lr0818 @ 2024-10-06 20:30:29

@Grammar__hbw 没听懂


by Grammar__hbw @ 2024-10-06 20:31:09

@lr0818 return x.d<x.d;

还有,你没定义a数组!!!!


by lr0818 @ 2024-10-06 20:31:44

看到了


by Grammar__hbw @ 2024-10-06 20:32:08

#include <bits/stdc++.h>
using namespace std;
const int N=307;
struct s{
    int a,e;
    long long d;
} a[N];
bool cmp(s x, s y) {
    if (x.e!=y.e)   return x.e>y.e;
    if (x.a!=y.a)   return x.a>y.a;
    return x.d<x.d;
}
int main() {
    long long n,b,c;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin>>a[i].a>>b>>c;
        a[i].d=i;
        a[i].e=a[i].a+b+c;
    }
    sort(a+1,a+n+1,cmp);
    for (int i = 1; i <= 5; i++) {
        cout<<a[i].d<<" "<<a[i].e<< "\n";
    }
    return 0;
}

by lr0818 @ 2024-10-06 20:32:43

#include <bits/stdc++.h>
using namespace std;
struct s{
    int a,e;
    long long d;
};
bool cmp(s x, s y) {
    if (x.e!=y.e)   return x.e>y.e;
    if (x.a!=y.a)   return x.a>y.a;
    return x.d<x.d;
}
int main() {
    long long n,b,c;
    cin >> n;
    int a[n+1];
    for (int i = 1; i <= n; i++) {
        cin>>a[i].a>>b>>c;
        a[i].d=i;
        a[i].e=a[i].a+b+c;
    }
    sort(a+1,a+n+1,cmp);
    for (int i = 1; i <= 5; i++) {
        cout<<a[i].d<<" "<<a[i].e<< "\n";
    }
    return 0;
}

还是不对


by lr0818 @ 2024-10-06 20:33:44

@Grammar__hbw


| 下一页