๐ก Info
๋ด์ฉ
๋ํ์ด๋ค ๋ฐ ํ์ N๋ช ์ ์ด๋ฆ๊ณผ ๊ตญ์ด, ์์ด, ์ํ ์ ์๊ฐ ์ฃผ์ด์ง๋ค. ์ด๋, ๋ค์๊ณผ ๊ฐ์ ์กฐ๊ฑด์ผ๋ก ํ์์ ์ฑ์ ์ ์ ๋ ฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
๐ฅ์ ๋ ฅ ์กฐ๊ฑด
12
Junkyu 50 60 100
Sangkeun 80 60 50
Sunyoung 80 70 100
Soong 50 60 90
Haebin 50 60 100
Kangsoo 60 80 100
Donghyuk 80 60 100
Sei 70 70 70
Wonseob 70 70 90
Sanghyun 70 70 80
nsj 80 80 80
Taewhan 50 60 90
๐ค์ถ๋ ฅ ์กฐ๊ฑด
Donghyuk
Sangkeun
Sunyoung
nsj
Wonseob
Sanghyun
Sei
Kangsoo
Haebin
Junkyu
Soong
Taewhan
์ค์ ํ์ด ์๊ฐ : 20๋ถ
์ ๋ ฅ
๊ณ์ฐ
์ถ๋ ฅ
๋ณ๋ ๋ฉ์๋
import java.util.*;
class Student implements Comparable<Student> {
static String name;
static int K;
static int E;
static int M;
public Student(String name, int K, int E, int M) {
this.name = name;
this.K = K;
this.E = E;
this.M = M;
}
public String getName() {
return this.name;
}
@Override
public int compareTo(Student other) {
if (this.K == other.K && this.E == other.E && this.M == other.M) {
return this.name.compareTo(other.name);
}
if (this.K == other.K && this.E == other.E) {
return Integer.compare(other.M, this.M);
}
if (this.K == other.K) {
return Integer.compare(this.E, other.E);
}
return Integer.compare(other.K, this.K);
}
}
public class Main {
static int N;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
ArrayList<Student> students = new ArrayList<>();
for (int i = 0; i < N; i++) {
String name = sc.next();
int K = sc.nextInt();
int E = sc.nextInt();
int M = sc.nextInt();
students.add(new Student(name, K, E, M));
}
Collections.sort(students);
for (int i = 0; i < N; i++) {
System.out.println(students.get(i).getName());
}
}
}
//before
class Student implements Comparable<Student> {
static String name;
static int K;
static int E;
static int M;
//after
class Student implements Comparable<Student> {
private String name;
private int K;
private int E;
private int M;
์ค์ ํ์ด ์๊ฐ : 30๋ถ(์ฒซ ํ์ด ์๊ฐ ํฌํจ)
์ ๋ ฅ
๊ณ์ฐ
์ถ๋ ฅ
๋ณ๋ ๋ฉ์๋
import java.util.*;
class Student implements Comparable<Student> {
private String name;
private int K;
private int E;
private int M;
public Student(String name, int K, int E, int M) {
this.name = name;
this.K = K;
this.E = E;
this.M = M;
}
public String getName() {
return this.name;
}
@Override
public int compareTo(Student other) {
if (this.K == other.K && this.E == other.E && this.M == other.M) {
return this.name.compareTo(other.name);
}
if (this.K == other.K && this.E == other.E) {
return Integer.compare(other.M, this.M);
}
if (this.K == other.K) {
return Integer.compare(this.E, other.E);
}
return Integer.compare(other.K, this.K);
}
}
public class Main {
static int N;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
ArrayList<Student> students = new ArrayList<>();
for (int i = 0; i < N; i++) {
String name = sc.next();
int K = sc.nextInt();
int E = sc.nextInt();
int M = sc.nextInt();
students.add(new Student(name, K, E, M));
}
Collections.sort(students);
for (int i = 0; i < N; i++) {
System.out.println(students.get(i).getName());
}
}
}