5176

#include <stdio.h>
#include <stdlib.h>

// 배열 초기화
void ArrayInitialization(int *arr, int size){
    for(int i = 0; i < size; i++){
        arr[i] = 0;
    }
}

int main(void){
    // 테스트 케이스 입력
    int test_case = 0;
    scanf("%d", &test_case);

    for(int i = 0; i < test_case; i++){
        // 참가자의 수, 자리의 수 입력
        int p = 0, m = 0;
        scanf("%d %d", &p, &m);

        int *seat_arr = (int*)malloc(sizeof(int)*m);
        ArrayInitialization(seat_arr, m);

        int count = 0;
        for(int j = 0; j < p; j++){
            // 참가자가 원하는 자리 입력
            int seat = 0;
            scanf("%d", &seat);

            // 해당 자리에 사람이 있으면
            // 참가하지 못하는 사람의 수 +1
            if(seat_arr[seat-1] == 1){
                count ++;
            }
            // 해당 자리에 사람이 없으면 1로 바꿈
            else{
                seat_arr[seat-1] = 1;    
            }
        }

        // 참가하지 못하는 사람의 수 출력
        printf("%d\n", count);
        free(seat_arr);
    }
}

+ Recent posts