[Java] SWEA 5431 민석이의 과제 체크하기

Lee GaEun·2024년 11월 15일

[Java] 알고리즘

목록 보기
19/93

5431 민석이의 과제 체크하기 문제 링크

문제분석

  • 어떤 번호의 사람이 제출했는지에 대한 목록을 받음
  • 과제를 제출하지 않은 사람의 번호를 오름차순으로 출력하라

제약 사항

  • 번호는 1이상 N이하의 정수임
  • 같은 번호가 두 번 이상 주어지는 경우는 없음

입력 조건

  • 첫째 줄 : 테스트 케이스 수 ( T <= 10 )
  • 둘째 줄 : 수강생의 수 N(2≤N≤100), 과제를 제출한 사람의 수 K(1≤K≤N)
  • 셋째 줄 : 과제를 제출한 사람의 번호 K개(공백으로 구분)

출력 조건

  • #부호 + 테스트 케이스 번호 + " " + 과제를 제출하지 않은 사람의 번호를 오름차순으로 출력

#1

import java.util.Scanner;
import java.io.FileInputStream;

class Solution
{
    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int T;
        T=sc.nextInt();

        for(int test_case = 1; test_case <= T; test_case++)
        {
            int N = sc.nextInt();
            int N2 = sc.nextInt();

            int[] arr = new int[N];

            for(int i=0; i<N2; i++) {
                int Index = sc.nextInt();
                arr[Index-1] = 1;
            }

            System.out.print("#" + test_case);
            for(int i=0; i<N; i++) {
                if(arr[i]==0) {
                    System.out.print(" " + (i+1));
                }
            }
            System.out.println();
        }
    }
}

  • 성공!
profile
I will give it my all (๑•̀o•́๑)ง

0개의 댓글