-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
50 lines (41 loc) · 1.16 KB
/
Solution.java
File metadata and controls
50 lines (41 loc) · 1.16 KB
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
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Player[] players;
Checker checker = new Checker();
try (Scanner sc = new Scanner(System.in)) {
int n = sc.nextInt();
players = new Player[n];
for (int i = 0; i < n; i++) {
players[i] = new Player(sc.next(), sc.nextInt());
}
}
Arrays.sort(players, checker);
for (Player player : players) {
System.out.printf("%s %s\n", player.getName(), player.getScore());
}
}
}
class Player {
private String name;
private int score;
public Player(String name, int score) {
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public int getScore() {
return score;
}
}
class Checker implements Comparator<Player> {
@Override
public int compare(Player p1, Player p2) {
if (p1.getScore() == p2.getScore()) return p1.getName().compareTo(p2.getName());
else return p2.getScore() - p1.getScore();
}
}