loading...

Daily HackerRank Challenge - Day 29

wingkwong profile image Wing-Kam Updated on ・1 min read

About

This is a series of Daily HackerRank Challenge. Each day I show the some solutions written in C++.


Comparator

image

Sample Input

5
amy 100
david 100
heraldo 50
aakansha 75
aleksa 150

Sample Output

aleksa 150
amy 100
david 100
aakansha 75
heraldo 50

Sort the score first, then sort the name.

Final Solution

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

Complete Code

Check out the complete code via below link

Posted on by:

wingkwong profile

Wing-Kam

@wingkwong

Consultant by day. Developer by night. AWS certified. Exploring #CloudNative currently.

Discussion

pic
Editor guide