90分 第一个样例为过 求调

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

ACE_OKK @ 2024-07-12 22:59:07

#include <bits/stdc++.h>
using namespace std;
struct node {
    char name[10];
    int ch,ma,en,sum;
}stu[1001]; 

bool cmp(node b,node c){
    return b.sum > c.sum;
}

int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s%d%d%d",stu[i].name,&stu[i].ch,&stu[i].ma,&stu[i].en);
        stu[i].sum = stu[i].ch+stu[i].ma+stu[i].en;
    }

    sort(stu+1,stu+n+1,cmp);
    printf("%s %d %d %d",stu[1].name,stu[1].ch,stu[1].ma,stu[1].en);

    return 0;
}

by Lfz312g @ 2024-07-12 23:05:36

//如果有多个总分相同的学生,输出靠前的那位。

#include <bits/stdc++.h>
using namespace std;
struct node {
    char name[10];
    int ch,ma,en,sum,id;
}stu[1001]; 

bool cmp(node b,node c){
    if (b.sum!=c.sum) return b.sum > c.sum;
    return b.id<c.id;
}

int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s%d%d%d",stu[i].name,&stu[i].ch,&stu[i].ma,&stu[i].en);
        stu[i].sum = stu[i].ch+stu[i].ma+stu[i].en;
        stu[i].id=i;
    }

    sort(stu+1,stu+n+1,cmp);
    printf("%s %d %d %d",stu[1].name,stu[1].ch,stu[1].ma,stu[1].en);
    return 0;
}

by Maisie586_ @ 2024-07-13 05:58:46

@ACE_OKK 求关

#include <bits/stdc++.h>

using namespace std;
struct abc{
    string name;
    int all_subject,chinese,math,english;
    int id;
}a[11100];
bool cmp(abc a,abc b)
{
    if(a.all_subject==b.all_subject){
        return a.id<b.id;
    } 
    return a.all_subject>b.all_subject; 
}

int main() {
    int t1,t2,t3;
    int n;
    string s; 
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >>s>> t1 >> t2 >> t3;
        a[i].name = s;
        a[i].chinese = t1;
        a[i].math = t2;
        a[i].english = t3;
        a[i].all_subject=t1+t2+t3;
        a[i].id=i;
    } 
    sort(a+1,a+1+n,cmp);
    cout << a[1].name << " "<<a[1].chinese;
    cout << " " << a[1].math << " " << a[1].english; 
}

by ACE_OKK @ 2024-07-13 23:21:17

@Maisie586_ 牛逼,已关!!!


|