-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
53 lines (46 loc) · 930 Bytes
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int id;
int chinese;
int math;
int english;
int score;
};
bool cmp(node a,node b)
{
if(a.score!=b.score)
return a.score > b.score;
else if(a.chinese != b.chinese)
return a.chinese > b.chinese;
else
return a.id < b.id;
}
node student[302];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n;i++)
{
cin >> student[i].chinese >> student[i].math >> student[i].english;
student[i].id = i;
student[i].score = student[i].chinese + student[i].math + student[i].english;
}
sort(student + 1, student + n+1, cmp);
if(n<5)
{
for (int i = 1; i <= n;i++)
{
cout << student[i].id << " " << student[i].score<<"\n";
}
}
for (int i = 1; i <= 5;i++)
{
cout << student[i].id << " " << student[i].score<<"\n";
}
return 0;
}