-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathtell-thepositions.cpp
89 lines (56 loc) · 1.48 KB
/
tell-thepositions.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Name: Mehul Chaturvedi
IIT-Guwahati
*/
/*
PROBLEM STATEMENT
In a class there are ‘n’ number of students. They have three different subjects: Data Structures, Algorithm Design & Analysis and Operating Systems.
Marks for each subject of all the students are provided to you. You have to tell the position of each student in the class.
Print the names of each student according to their position in class. Tie is broken on the basis of their roll numbers. Between two students having same marks,
the one with less roll number will have higher rank. The input is provided in order of roll number.
*/
#include <bits/stdc++.h>
using namespace std;
class student{
public:
string name;
int marks;
int roll;
};
bool mycompare(student a, student b){
if (a.marks!=b.marks)
{
return (a.marks>b.marks);
}else{
return(a.roll<b.roll);
}
}
int main( int argc , char ** argv )
{
ios_base::sync_with_stdio(false) ;
cin.tie(NULL) ;
int n;
std::cin>>n;
//std::vector<string> name; //ncross1
std::vector<student> stud; //ncross3
for (int i = 0; i < n; ++i)
{
string temp_name;
int sub1;
int sub2;
int sub3;
cin>>temp_name>>sub1>>sub2>>sub3;
int sum = sub1+sub2+sub3;
student temp_sub;
temp_sub.name = temp_name;
temp_sub.marks = sum;
temp_sub. roll = i+1;
stud.push_back(temp_sub);
}
sort(stud.begin(), stud.end(), mycompare);
for (int i = 0; i < n; ++i)
{
cout << i+1<<" "<<stud.at(i).name<<'\n';
}
return 0 ;
}