forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path11.java
53 lines (41 loc) ยท 1.17 KB
/
11.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
43
44
45
46
47
48
49
50
51
52
53
import java.util.*;
class Student implements Comparable<Student> {
private String name;
private int score;
public Student(String name, int score) {
this.name = name;
this.score = score;
}
public String getName() {
return this.name;
}
public int getScore() {
return this.score;
}
// ์ ๋ ฌ ๊ธฐ์ค์ '์ ์๊ฐ ๋ฎ์ ์์'
@Override
public int compareTo(Student other) {
if (this.score < other.score) {
return -1;
}
return 1;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// N์ ์
๋ ฅ๋ฐ๊ธฐ
int n = sc.nextInt();
// N๋ช
์ ํ์ ์ ๋ณด๋ฅผ ์
๋ ฅ๋ฐ์ ๋ฆฌ์คํธ์ ์ ์ฅ
List<Student> students = new ArrayList<>();
for (int i = 0; i < n; i++) {
String name = sc.next();
int score = sc.nextInt();
students.add(new Student(name, score));
}
Collections.sort(students);
for (int i = 0; i < students.size(); i++) {
System.out.print(students.get(i).getName() + " ");
}
}
}