백준

박경희·2024년 1월 18일

코딩테스트

목록 보기
25/69

5597

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);

        // 1번부터 30번까지 번호를 추적하는 배열 (false:미제출, true: 제출)
        boolean[] submitted = new boolean[31]; //인덱스 1부터 사용

        //제출한 학생 번호 입력받기
        for (int i = 0; i < 28; i++) {
            int number = sc.nextInt();
            submitted[number] = true;
        }

        // 제출하지 않은 번호 출력
        for (int i = 1; i < submitted.length; i++) {
            if (!submitted[i]) {
                System.out.println(i);
            }
        }
    }
}

3052

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);

        // 서로 다른 나머지를 저장할 HashSet 생성
        HashSet<Integer> remainders = new HashSet<>();

        // 10개의 숫자를 입력 받고 나머지 계산한 값을 set에 추가
        for (int i = 0; i < 10; i++) {
            int n = sc.nextInt();
            remainders.add(n % 42);
        }
        System.out.println(remainders.size());
    }
}

10811

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);

       int N = sc.nextInt();
       int M = sc.nextInt();

       //바구니 배열 초기화
       int[] baskets = new int[N];
        for (int i = 0; i < N; i++) {
            baskets[i] = i + 1;
        }

        for (int m = 0; m < M; m++) {
            int k = sc.nextInt() -1; // 입력을 0 로 변환
            int j = sc.nextInt() -1;

            // [i, j] 범위의 바구니 순서를 역순으로 변경
            while (k < j) {
                int temp = baskets[k];
                baskets[k] = baskets[j];
                baskets[j] = temp;
                k++;
                j--;
            }
        }
        for (int basket : baskets) {
            System.out.print(basket + " ");
        }
    }
}

0개의 댓글