-
Notifications
You must be signed in to change notification settings - Fork 80
/
comparator_sorting.cpp
50 lines (45 loc) · 1 KB
/
comparator_sorting.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
#include<cmath>
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
struct Player {
int score;
string name;
};
class Checker{
public:
static int comparator(Player a, Player b){
if(a.score == b.score)
if (a.name == b.name)
return 0;
else
return ( a.name > b.name )? -1:1;
return (a.score<b.score)?-1:1;
}
};
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;
}