forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1.java
67 lines (56 loc) ยท 1.92 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.*;
class Student implements Comparable<Student> {
private String name;
private int kor;
private int eng;
private int m;
public Student(String name, int kor, int eng, int m) {
this.name = name;
this.kor = kor;
this.eng = eng;
this.m = m;
}
/*
[ ์ ๋ ฌ ๊ธฐ์ค ]
1) ๋ ๋ฒ์งธ ์์๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ
2) ๋ ๋ฒ์งธ ์์๊ฐ ๊ฐ์ ๊ฒฝ์ฐ, ์ธ ๋ฒ์งธ ์์๋ฅผ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌ
3) ์ธ ๋ฒ์งธ ์์๊ฐ ๊ฐ์ ๊ฒฝ์ฐ, ๋ค ๋ฒ์งธ ์์๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ
4) ๋ค ๋ฒ์งธ ์์๊ฐ ๊ฐ์ ๊ฒฝ์ฐ, ์ฒซ ๋ฒ์งธ ์์๋ฅผ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌ
*/
public String getName() {
return this.name;
}
// ์ ๋ ฌ ๊ธฐ์ค์ '์ ์๊ฐ ๋ฎ์ ์์'
@Override
public int compareTo(Student other) {
if (this.kor == other.kor && this.eng == other.eng && this.m == other.m) {
return this.name.compareTo(other.name);
}
if (this.kor == other.kor && this.eng == other.eng) {
return Integer.compare(other.m, this.m);
}
if (this.kor == other.kor) {
return Integer.compare(this.eng, other.eng);
}
return Integer.compare(other.kor, this.kor);
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Student> students = new ArrayList<>();
for (int i = 0; i < n; i++) {
String name = sc.next();
int kor = sc.nextInt();
int eng = sc.nextInt();
int m = sc.nextInt();
students.add(new Student(name, kor, eng, m));
}
Collections.sort(students);
// ์ ๋ ฌ๋ ํ์ ์ ๋ณด์์ ์ด๋ฆ๋ง ์ถ๋ ฅ
for (int i = 0; i < n; i++) {
System.out.println(students.get(i).getName());
}
}
}