You are viewing a single comment's thread. Return to all comments →
class Checker implements Comparator{ @Override public int compare(Player p1,Player p2){
if(p1.score==p2.score){ return p1.name.compareTo(p2.name); } else if(p1.score>p2.score){ return -1; } else return 1; }
}
public class Solution {
public static void main(String[] args) { Scanner in =new Scanner(System.in); int numberOfPlayer=in.nextInt(); List<Player> playerList=new ArrayList<Player>(); Checker checker=new Checker(); while(numberOfPlayer>0){ String name=in.next(); int score=in.nextInt(); Player player=new Player(name,score); playerList.add(player); numberOfPlayer--; } Collections.sort(playerList,checker); for(Player p:playerList){ System.out.println(p.name+" "+p.score); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Comparator
You are viewing a single comment's thread. Return to all comments →
class Checker implements Comparator{ @Override public int compare(Player p1,Player p2){
}
public class Solution {
}