题解

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 CuSObin_BiNSO4 @ 2022-02-11 11:57:23

nb,tlqtj都有了


by Enderich @ 2022-02-11 11:58:04

tlqtj,jbl


by Dream_weavers @ 2022-02-11 12:01:00

tlqtj。。。


by m256i @ 2022-02-11 12:28:12


by Engulf @ 2022-02-11 12:30:40


by MrCR7 @ 2022-02-11 12:59:56

@waioi_lin 违规紫衫吧


by waioi_lin @ 2022-02-11 19:29:34

@MrCR7 你咋看到的?(不知为何,博客发不了)


by MrCR7 @ 2022-02-11 19:38:31

@waioi_lin 题目的题解数目已经满了,发不了了……


by waioi_lin @ 2022-02-11 19:56:18

@MrCR7 恍然大悟


by waioi_lin @ 2022-02-11 19:58:33

@MrCR7 在这发题解算社区贡献吗?


| 下一页