0%

HackerRank Sorting 3.Comparator

題目連結:Sorting: Comparator | HackerRank

比較函式的撰寫

1
2
3
4
5
6
7
8
9
10
11
12
struct Player {
int score;
string name;
};

class Checker{
public:
static int comparator(Player a, Player b) {
if(a.score!=b.score) return a.score>b.score?0:-1;
return a.name<b.name?0:-1;
}
};