-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSorting_Comparator.cpp
61 lines (55 loc) · 1.14 KB
/
Sorting_Comparator.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
#include<cmath>
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
struct Player {
int score;
string name;
};
class Checker{
public:
// complete this method
static int comparator(Player a, Player b) {
if(a.score > b.score){
return 1;
}
else if(a.score < b.score){
return -1;
}
else if(a.name > b.name){
return -1;
}
else if(a.name < b.name){
return 1;
}
else{
return 0;
}
}
};
bool compare(Player a, Player b) {
if(Checker::comparator(a,b) == -1)
return false;
return true;
}
int main()
{
int n;
cin >> n;
vector< Player > players;
string name;
int score;
for(int i = 0; i < n; i++){
cin >> name >> score;
Player player;
player.name = name, player.score = score;
players.push_back(player);
}
sort(players.begin(), players.end(), compare);
for(int i = 0; i < players.size(); i++) {
cout << players[i].name << " " << players[i].score << endl;
}
return 0;
}