天天看點

洛谷P1093獎學金

繼續水一波

#include <bits/stdc++.h>

using namespace std;

const int N = 310;

struct Student
{
    int id;
    int chinese,math,english;
    int score;
}st[N];

bool cmp(Student a,Student b)
{
    if(a.score != b.score)  return a.score > b.score;
    if(a.chinese != b.chinese)  return a.chinese > b.chinese;
    return a.id < b.id;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0;i < n;i ++)   
    {
        cin >> st[i].chinese >> st[i].math >> st[i].english;
        st[i].id = i + 1;
        st[i].score = st[i].chinese + st[i].math + st[i].english;
    }
    sort(st,st + n,cmp);
    for(int i = 0;i < 5;i ++)   cout << st[i].id << ' ' << st[i].score << endl;
    return 0;
}