题解

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

waioi_lin @ 2022-02-11 11:56:41

#include <bits/stdc++.h>
#define itn int
#define ll long long
#define retrun return
using namespace std;

int in(){
    char c = getchar();
    int x = 0, f = 1;
    for (; c < '0' || c > '9'; c = getchar())
        if (c == '-') f = -1;
    for (; c >= '0' && c <= '9'; c = getchar())
        x = (x << 1) + (x << 3) + (c ^ 48);
    return x * f;
}

void pr(int x){
    if (x < 0) x = -x, putchar('-');
    if (x > 9) pr(x / 10);
    putchar(x % 10 + '0');
}

struct Node{
    string name;
    int Chinese;
    int Math;
    int English;
    int xuhao;
}; 

bool cmp(Node a, Node b){
    int a1,b1;
    a1=a.Chinese+a.English+a.Math;
    b1=b.Chinese+b.English+b.Math;
    if (a1!=b1) 
        return a1 > b1;
    else
        return a.xuhao < b.xuhao;
}

int  main(void){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    int n;
    scanf("%d", &n);
    Node a[n];
    for(int i=0;i<n;i++){
        cin>>a[i].name>>a[i].Chinese>>a[i].Math>>a[i].English;
        a[i].xuhao=i;
    }
    sort(a,a+n,cmp);
    cout<<a[0].name<<" "<<a[0].Chinese<<" "<<a[0].Math<<" "<<a[0].English<<endl;
    return (0);
}

by MrCR7 @ 2022-02-11 20:02:06

@waioi_lin 不算,还有可能被封号,因为你违规了洛谷社区规则


by waioi_lin @ 2022-02-11 20:28:17

@MrCR7 为啥?啥规则


by MrCR7 @ 2022-02-11 20:35:48

@waioi_lin 反正肯定不算贡献


by MrCR7 @ 2022-02-11 20:36:03

@waioi_lin 你可以去私信chen_zhe


by Cddaza000 @ 2022-09-23 11:05:16

@waioi_lin 不让tlqtj啊..


上一页 |