forked from sushish-kumar/cpp-hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.cpp
58 lines (43 loc) · 1020 Bytes
/
sort.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
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
class player {
public:
player(string name, int score): name_(name), score_(score){}
string get_name() const{
return name_;
}
int get_score() const{
return score_;
}
void print() const{
cout << name_ << " " << score_ << '\n';
}
private:
string name_;
int score_;
};
bool compare_players(player const & p1, player const & p2){
if (p1.get_score() > p2.get_score()) return true;
else if (p1.get_score() == p2.get_score()) return p1.get_name() < p2.get_name();
else return false;
}
int main(){
int n;
cin >> n;
vector<player> arr;
for (int i = 0; i < n; i++){
string name;
int score;
cin >> name >> score;
player tmp(name, score);
arr.push_back(tmp);
}
sort(arr.begin(), arr.end(), compare_players);
for (player const & el: arr){
el.print();
}
return 0;
}