📍 문제 설명
💡 접근
조건에 따라 정렬시키면 된다.
👩💻 코드
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
ArrayList<Student> list = new ArrayList<Student>();
for(int i = 0; i < n; i++) {
list.add(new Student(kb.next(), kb.nextInt(), kb.nextInt(), kb.nextInt()));
}
Collections.sort(list);
for(Student s : list) {
System.out.println(s.name);
}
}
private static class Student implements Comparable<Student> {
private String name;
private int korean;
private int english;
private int math;
public Student(String name, int korean, int english, int math) {
this.name = name;
this.korean = korean;
this.english = english;
this.math = math;
}
@Override
public int compareTo(Student o) {
if (this.korean == o.korean) {
if(this.english == o.english) {
if(this.math == o.math) {
return this.name.compareTo(o.name);
}
return o.math - this.math;
}
return this.english - o.english;
}
return o.korean - this.korean;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", korean=" + korean +
", math=" + math +
", english=" + english +
'}';
}
}
}