๐Ÿฅˆ [Baekjoon / Java] 10825. ๊ตญ์˜์ˆ˜

์ดํ•˜์–€ยท2024๋…„ 7์›” 14์ผ
0

๐Ÿฃ ๋ฐฑ์ค€

๋ชฉ๋ก ๋ณด๊ธฐ
32/33

๋ฌธ์ œ ์„ค๋ช…


๐Ÿ’ก Info

๋‚ด์šฉ

๋„ํ˜„์ด๋„ค ๋ฐ˜ ํ•™์ƒ N๋ช…์˜ ์ด๋ฆ„๊ณผ ๊ตญ์–ด, ์˜์–ด, ์ˆ˜ํ•™ ์ ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์กฐ๊ฑด์œผ๋กœ ํ•™์ƒ์˜ ์„ฑ์ ์„ ์ •๋ ฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

  1. ๊ตญ์–ด ์ ์ˆ˜๊ฐ€ ๊ฐ์†Œํ•˜๋Š” ์ˆœ์„œ๋กœ
  2. ๊ตญ์–ด ์ ์ˆ˜๊ฐ€ ๊ฐ™์œผ๋ฉด ์˜์–ด ์ ์ˆ˜๊ฐ€ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆœ์„œ๋กœ
  3. ๊ตญ์–ด ์ ์ˆ˜์™€ ์˜์–ด ์ ์ˆ˜๊ฐ€ ๊ฐ™์œผ๋ฉด ์ˆ˜ํ•™ ์ ์ˆ˜๊ฐ€ ๊ฐ์†Œํ•˜๋Š” ์ˆœ์„œ๋กœ
  4. ๋ชจ๋“  ์ ์ˆ˜๊ฐ€ ๊ฐ™์œผ๋ฉด ์ด๋ฆ„์ด ์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ฆ๊ฐ€ํ•˜๋Š” ์ˆœ์„œ๋กœ (๋‹จ, ์•„์Šคํ‚ค ์ฝ”๋“œ์—์„œ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋ณด๋‹ค ์ž‘์œผ๋ฏ€๋กœ ์‚ฌ์ „์ˆœ์œผ๋กœ ์•ž์— ์˜จ๋‹ค.)

๐Ÿ“ฅ์ž…๋ ฅ ์กฐ๊ฑด

  • ์ฒซ์งธ ์ค„์— ๋„ํ˜„์ด๋„ค ๋ฐ˜์˜ ํ•™์ƒ์˜ ์ˆ˜ N (1 โ‰ค N โ‰ค 100,000)์ด ์ฃผ์–ด์ง„๋‹ค.
  • ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ๊ฐ ํ•™์ƒ์˜ ์ด๋ฆ„, ๊ตญ์–ด, ์˜์–ด, ์ˆ˜ํ•™ ์ ์ˆ˜๊ฐ€ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด ์ฃผ์–ด์ง„๋‹ค.
  • ์ ์ˆ˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 100๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค.
  • ์ด๋ฆ„์€ ์•ŒํŒŒ๋ฒณ ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด์ด๊ณ , ๊ธธ์ด๋Š” 10์ž๋ฆฌ๋ฅผ ๋„˜์ง€ ์•Š๋Š”๋‹ค.
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

๐Ÿ“ค์ถœ๋ ฅ ์กฐ๊ฑด

  • ๋ฌธ์ œ์— ๋‚˜์™€์žˆ๋Š” ์ •๋ ฌ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ ํ›„ ์ฒซ์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์— ๊ฑธ์ณ ๊ฐ ํ•™์ƒ์˜ ์ด๋ฆ„์„ ์ถœ๋ ฅํ•œ๋‹ค.
Donghyuk
Sangkeun
Sunyoung
nsj
Wonseob
Sanghyun
Sei
Kangsoo
Haebin
Junkyu
Soong
Taewhan


๋ฌธ์ œ ์ดํ•ด


  • ์ฃผ์–ด์ง„ ์กฐ๊ฑด๋“ค์„ ๋ชจ๋‘ ๋งŒ์กฑํ•˜๋Š” ์ •๋ ฌ ์ง„ํ–‰ํ•˜๊ธฐ!


์•Œ๊ณ ๋ฆฌ์ฆ˜


์‹ค์ œ ํ’€์ด ์‹œ๊ฐ„ : 20๋ถ„

  • ์ž…๋ ฅ

    • N ์ž…๋ ฅ๋ฐ›๊ธฐ
  • ๊ณ„์‚ฐ

    • ๊ตญ์–ด ์ ์ˆ˜ ๋น„๊ต
    • ๊ตญ์–ด ์ ์ˆ˜๊ฐ€ ๊ฐ™์€ ๊ฒฝ์šฐ โžก๏ธ ์˜์–ด ์ ์ˆ˜ ๋น„๊ต
    • ์˜์–ด ์ ์ˆ˜ ๊ฐ™์€ ๊ฒฝ์šฐ โžก๏ธ ์ˆ˜ํ•™ ์ ์ˆ˜ ๋น„๊ต
    • ์„ธ ์ ์ˆ˜ ๋™์ผํ•ด์ง€๋ฉด โžก๏ธ ์ด๋ฆ„์œผ๋กœ ์ •๋ ฌ
  • ์ถœ๋ ฅ

    • ์ •๋ ฌ์ด ์™„๋ฃŒ๋œ ํ•™์ƒ ์ด๋ฆ„ ์ถœ๋ ฅํ•˜๊ธฐ
  • ๋ณ„๋„ ๋ฉ”์„œ๋“œ

    • Comparable๋กœ ์ •๋ ฌ ๊ธฐ์ค€ ์„ค์ •ํ•˜๊ธฐ
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());
        }
    }
}


์˜ค๋‹ต์ฒดํฌ


  • ๊ฐ™์€ ํ•™์ƒ์˜ ์ด๋ฆ„๋งŒ ์ถœ๋ ฅ๋˜๋Š” ๋ฌธ์ œ ๋ฐœ์ƒ
    • static์„ ํ†ตํ•ด ์ „์—ญ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•œ ๋ถ€๋ถ„์ด ๋ฌธ์ œ -> static ์‚ญ์ œ
//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๋ถ„(์ฒซ ํ’€์ด ์‹œ๊ฐ„ ํฌํ•จ)

  • ์ž…๋ ฅ

    • N ์ž…๋ ฅ๋ฐ›๊ธฐ
  • ๊ณ„์‚ฐ

    • ๊ตญ์–ด ์ ์ˆ˜ ๋น„๊ต
    • ๊ตญ์–ด ์ ์ˆ˜๊ฐ€ ๊ฐ™์€ ๊ฒฝ์šฐ โžก๏ธ ์˜์–ด ์ ์ˆ˜ ๋น„๊ต
    • ์˜์–ด ์ ์ˆ˜ ๊ฐ™์€ ๊ฒฝ์šฐ โžก๏ธ ์ˆ˜ํ•™ ์ ์ˆ˜ ๋น„๊ต
    • ์„ธ ์ ์ˆ˜ ๋™์ผํ•ด์ง€๋ฉด โžก๏ธ ์ด๋ฆ„์œผ๋กœ ์ •๋ ฌ
  • ์ถœ๋ ฅ

    • ์ •๋ ฌ์ด ์™„๋ฃŒ๋œ ํ•™์ƒ ์ด๋ฆ„ ์ถœ๋ ฅํ•˜๊ธฐ
  • ๋ณ„๋„ ๋ฉ”์„œ๋“œ

    • Comparable๋กœ ์ •๋ ฌ ๊ธฐ์ค€ ์„ค์ •ํ•˜๊ธฐ
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());
        }
    }
}

profile
์–ธ์  ๊ฐ€ ๋‚ด ์ฝ”๋“œ๋กœ ์„ธ์ƒ์— ๊ธฐ์—ฌํ•  ์ˆ˜ ์žˆ๋„๋ก, BE ๊ฐœ๋ฐœ ๊ธฐ๋ก ๋…ธํŠธโ˜˜๏ธ

0๊ฐœ์˜ ๋Œ“๊ธ€