-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort_It.cpp
More file actions
56 lines (53 loc) · 1.05 KB
/
Sort_It.cpp
File metadata and controls
56 lines (53 loc) · 1.05 KB
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
54
55
56
#include <bits/stdc++.h>
using namespace std;
class student
{
public:
string nm;
int cls;
char s;
int id;
int math_marks;
int eng_marks;
};
bool cmp(student l, student r)
{
if (l.math_marks + l.eng_marks == r.math_marks + r.eng_marks)
{
if (l.id < r.id)
{
return true;
}
else
{
return false;
}
}
else
{
if (l.math_marks + l.eng_marks > r.math_marks + r.eng_marks)
{
return true;
}
else
{
return false;
}
}
}
int main()
{
int n;
cin >> n;
student a[n];
for (int i = 0; i < n; i++)
{
cin >> a[i].nm >> a[i].cls >> a[i].s >> a[i].id >> a[i].math_marks >> a[i].eng_marks;
}
sort(a, a + n, cmp);
for (int i = 0; i < n; i++)
{
cout << a[i].nm << " " << a[i].cls << " " << a[i].s << " " << a[i].id << " " << a[i].math_marks << " " << a[i].eng_marks << endl;
}
return 0;
}