ddubi

[백준] 5597번 : 과제 안내신분..? feat. java 본문

코테 문제풀이

[백준] 5597번 : 과제 안내신분..? feat. java

ddubi__ 2022. 11. 30. 17:32

https://www.acmicpc.net/problem/5597 

 

5597번: 과제 안 내신 분..?

X대학 M교수님은 프로그래밍 수업을 맡고 있다. 교실엔 학생이 30명이 있는데, 학생 명부엔 각 학생별로 1번부터 30번까지 출석번호가 붙어 있다. 교수님이 내준 특별과제를 28명이 제출했는데,

www.acmicpc.net


풀이 ➡️ 메모리 초과

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class back_5597 {
    public static void main(String[] args) throws IOException {a
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Integer> list = new ArrayList<>();
        for(int i=0; i<28; i++){
            list.add(Integer.parseInt(br.readLine()));
        }
        Collections.sort(list);
        ArrayList<Integer> answer = new ArrayList<>();
        for(int i=0; i<30; i++){
            int num = i+1;
            int target = list.get(i);
            if(num != target){
                answer.add(num);
                Collections.sort(list);
                i --;
            }
        }
        System.out.println(answer);
    }
}

 

 

➡️ 풀이

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class back_5597 { // 과제 안내신 분 ..?
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        boolean[] totalList = new boolean[30];

        for(int i=0; i<28; i++){
            totalList[Integer.parseInt(br.readLine().trim())-1] = true;
        }
        for(int i=0; i<totalList.length; i++){
            if(!totalList[i]) System.out.println(i+1);
        }
    }
}

직관적으로 푸니까 풀린다..

 

Comments