관리 메뉴

cyphen156

백준-이분 탐색 10816 숫자 카드 2 본문

컴퓨터공학/알고리듬 풀이

백준-이분 탐색 10816 숫자 카드 2

cyphen156 2025. 8. 22. 14:24

숫자 카드 2

N개의 정수 배열이 있다.

이중 M개의 정수를 입력받았을 때 해당 숫자의 카드 갯수를 출력하라. 

제약사항

  • 1 <= N, M < 500,001
  • -10,000,000 <= value < 10,000,001

주의 사항

없다.

CPP풀이

숫자 카드 2_10816.cpp

/**
 * 백준 숫자 카드 2_10816
 * N개의 정수 배열이 있다.
 * 이중 M개의 정수를 입력받았을 때 존재하는 숫자 개수를 구하라. 
 * 
 * 제한사항
 *****************************************
 * 1 <= N, M < 500,001                   *
 * -10,000,000 <= value < 10,000,001     *
 *****************************************
 *
 *
 *
 * 주의
 * 없다.
 * 
 * 풀이시간 (문제 해석 + 구현)
 * 1 + 5분
 */


#include <iostream>

using namespace std;

static const int MAX_SIZE   = 20000001;
static const int OFFSET     = 10000000;

static int N, M;
static int inputs[MAX_SIZE] = { 0 };

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    cin >> N;

    for (int i = 0; i < N; ++i)
    {
        int input;
        cin >> input;
        inputs[input + OFFSET]++;
    }

    cin >> M;

    for (int i = 0; i < M; ++i)
    {
        int input;
        cin >> input;
        cout << inputs[input + OFFSET] << ' ';
    }
    cout << endl;
    return 0;
}

모든 예제 코드의 소스파일은 제 개인 깃허브 레포지토리에 있습니다.

 

Workspace/알고리듬 풀이 at main · cyphen156/Workspace

Studying . Contribute to cyphen156/Workspace development by creating an account on GitHub.

github.com