We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
struct Player{
public string name {get; set;}
public int score {get; set;}
public Player(string playerName, int playerScore){
name = playerName;
score = playerScore;
}
}
class Checker : IComparer<Player>{
public int Compare(Player a, Player b){
if(b.score != a.score)
return b.score.CompareTo(a.score);
return a.name.CompareTo(b.name);
}
}
static void Main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
int n = Convert.ToInt32(Console.ReadLine());
var players = new Player[n];
for (int i = 0; i < n; i++)
{
string[] input = Console.ReadLine().Split();
players[i] = ( new Player { name = input[0], score = Convert.ToInt32(input[1])});
}
//var list = players.OrderByDescending(p => p.score).ThenBy(p => p.name);
Array.Sort(players, new Checker());
foreach(var player in players)
{
Console.WriteLine($"{player.name} {player.score}");
}
Console.ReadLine();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Sorting: Comparator
You are viewing a single comment's thread. Return to all comments →
C#
class Solution {
}