50分,用的结构体,哪里错了呢,求大佬5555
查看原帖
50分,用的结构体,哪里错了呢,求大佬5555
474401
qwe1471900575楼主2021/3/4 01:25
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
struct student
{
    int id;
    int chinese;
    int sum;
};
int cmp(student a, student b)//******
{
    return a.sum > b.sum;
    return a.chinese > b.chinese;
    return a.id < b.id;
}
student a[350];
int main()
{
    freopen("sb.in", "r", stdin);
    freopen("sb.out", "w", stdout);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int math, english;
        cin >> a[i].chinese >> math >> english;
        a[i].sum = math + english + a[i].chinese;
        a[i].id = i + 1;
    }
    sort(a, a + n, cmp);
    for (int i = 0; i < 5; i++)
    {
        cout << a[i].id << " " << a[i].sum << endl;
    }
    return 0;
}
2021/3/4 01:25
加载中...