๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • ์žฅ์›์ต ๊ธฐ์ˆ ๋ธ”๋กœ๊ทธ
๐Ÿ’ป Computer Science/- Data Structure, Algorithm

[์•Œ๊ณ ๋ฆฌ์ฆ˜ PS(๋ฐฑ์ค€)] 10825๋ฒˆ ๊ตญ์˜์ˆ˜ ์ž๋ฐ” ๋ฌธ์ œ ํ’€์ด(Comparable ์žฌ์ •์˜)

by Wonit 2020. 6. 20.
import java.io.*;
import java.util.*;

public class Prob12_TestResult {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(br.readLine());
        List<Student_Prob12> list = new ArrayList<>();

        for(int i = 0; i < n; i++){
            StringTokenizer st = new StringTokenizer(br.readLine());
            Student_Prob12 student = new Student_Prob12(st.nextToken(),
                    Integer.parseInt(st.nextToken()),
                    Integer.parseInt(st.nextToken()),
                    Integer.parseInt(st.nextToken()));

            list.add(student);
        }
        Collections.sort(list);

        for(Student_Prob12 iter : list) {
            System.out.println(iter.name);
        }
    }
}

class Student_Prob12 implements Comparable<Student_Prob12>{
    String name;
    int korean;
    int english;
    int math;

    Student_Prob12(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_Prob12 o) {
        if(this.korean > o.korean) return -1; // ๊ตญ์–ด ์ ์ˆ˜ ๋‚ด๋ฆผ ์ฐจ์ˆœ
        else if(this.korean == o.korean) {
            if(this.english > o.english) return 1; // ์˜์–ด ์ ์ˆ˜ ๋‚ด๋ฆผ ์ฐจ์ˆœ

            else if(this.english == o.english){
                if(this.math > o.math) return -1;
                else if(this.math == o.math) {
                    return this.name.compareTo(o.name);
                }
                else return 1;
            }
            else return -1;
        }
        else return 1;
    }
}

๋Œ“๊ธ€