零分求助,AC必关

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

taoruiguo120 @ 2024-09-29 16:49:50

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

struct stu {
    string n;
    int sw, yw, yy;
    int sum;
} st[1010];

bool cmp(stu x, stu y) {
    return x.sum > y.sum;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> st[i].n >> st[i].sw >> st[i].yw >> st[i].yy;
        st[i].sum = st[i].sw + st[i].yw + st[i].yy;
    }
    sort(st, st + n, cmp);
    for (int i = 0; i <= 1 ; i++) {
        cout << st[i].n << " " << st[i].sw << " " << st[i].yw << " " << st[i].yy;
    }
    return 0;
}

零分求助,AC必关


by _8008008 @ 2024-09-29 16:54:45

qp


by InfiniteRobin @ 2024-09-29 16:55:52

@taoruiguo120

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

struct stu {
    string n;
    int sw, yw, yy;
    int sum,id;
} st[1010];

bool cmp(stu x, stu y) {
  //这里
    if(x.sum==y.sum){
        return x.id < y.id;
    }
    return x.sum > y.sum;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> st[i].n >> st[i].sw >> st[i].yw >> st[i].yy;
        st[i].sum = st[i].sw + st[i].yw + st[i].yy;
        st[i].id=i;、、这里
    }
    sort(st, st + n, cmp);
               //这里
    for (int i = 0; i < 1 ; i++) {
        cout << st[i].n << " " << st[i].sw << " " << st[i].yw << " " << st[i].yy;
    }
    return 0;
}

by _8008008 @ 2024-09-29 16:58:29

@taoruiguo120

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

struct stu {
    string n;
    int sw, yw, yy;
    int sum;
    int id;
} st[1010];

bool cmp(stu x, stu y) {
    if(x.sum==y.sum)return x.id<y.id;
    return x.sum > y.sum;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> st[i].n >> st[i].sw >> st[i].yw >> st[i].yy;
        st[i].sum = st[i].sw + st[i].yw + st[i].yy;
        st[i].id=i;
    }
    sort(st, st + n, cmp);
    for (int i = 0; i <= 0 ; i++) {
        cout << st[i].n << " " << st[i].sw << " " << st[i].yw << " " << st[i].yy;
    }
    return 0;
}

by taoruiguo120 @ 2024-09-29 16:59:09

@InfiniteRobin 谢谢,必关


by taoruiguo120 @ 2024-09-29 17:03:36

@_8008008 谢谢,必关


by xiaozou_ @ 2024-10-07 13:53:53

#include<bits/stdc++.h>
using namespace std;
struct mml
{
    string name;
    int yu,s,yi;//语数英
};
mml students[1010];
int main(){
    int n,i,m=-1,max;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>students[i].name>>students[i].yu>>students[i].s>>students[i].yi;
        if(m<students[i].yu+students[i].s+students[i].yi ){
            m=students[i].yu+students[i].s+students[i].yi;
            max=i;
        }
    }
    cout<<students[max].name<<' '<<students[max].yu<<' '<<students[max].s<<' '<<students[max].yi;
    return 0;
}

|