自测全对,但第一点WA!

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

IAKIOI66666 @ 2024-05-15 19:26:00

#include<bits/stdc++.h>
#define MAX 10000
using namespace std;
struct Record{
    string s;
    int a,b,c,x=-1,y;
}a[MAX];
int n,cnt;
int cmp(Record a,Record b){
    return a.x>b.x;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].s>>a[i].a>>a[i].b>>a[i].c;
        a[i].x=a[i].a+a[i].b+a[i].c;a[i].y=i;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++){
        if(a[i].x==a[1].x&&a[i].y<a[1].y)cnt=i;
    }
    if(cnt==0){
        cout<<a[1].s<<' '<<a[1].a<<' '<<a[1].b<<' '<<a[1].c;return 0;
    }
    else cout<<a[cnt].s<<' '<<a[cnt].a<<' '<<a[cnt].b<<' '<<a[cnt].c;
    return 0;
}

by CodeAnythingNow @ 2024-05-15 19:41:23

you正在努力逆袭中,待you与IOI大战,登上巨佬宝座,带上神犇光环,凯旋归来!!!

@IAKIOI66666

#include <bits/stdc++.h>
#define MAX 10000
using namespace std;

struct Record {
    string s;
    int a, b, c, x = -1, y;
} a[MAX];

int n, cnt;

bool cmp(Record a, Record b) {
    if (a.x != b.x) {
        return a.x > b.x;
    } else {
        return a.y < b.y;
    }
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].s >> a[i].a >> a[i].b >> a[i].c;
        a[i].x = a[i].a + a[i].b + a[i].c;
        a[i].y = i;
    }

    sort(a + 1, a + n + 1, cmp);

    cout << a[1].s << ' ' << a[1].a << ' ' << a[1].b << ' ' << a[1].c;

    return 0;
}

by IAKIOI66666 @ 2024-05-15 19:48:40

谢谢 @CodeAnythingNow


|