-
Notifications
You must be signed in to change notification settings - Fork 843
/
11.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() + " ");
}
}
}