-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy path[05]_1.java
42 lines (33 loc) · 808 Bytes
/
[05]_1.java
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
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
class Node {
public int age;
public String name;
public Node(int age, String name) {
this.age = age;
this.name = name;
}
}
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Node> data = new ArrayList<Node>();
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
String y = sc.next();
data.add(new Node(x, y));
}
Collections.sort(data, new Comparator<Node>() {
@Override
public int compare(Node a, Node b) {
return Integer.compare(a.age, b.age);
}
});
for (Node node: data) {
System.out.println(node.age + " " + node.name);
}
}
}