관리 메뉴

cyphen156

백준-집합과 맵 10816 숫자 카드2 본문

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

백준-집합과 맵 10816 숫자 카드2

cyphen156 2025. 5. 13. 19:57

숫자 카드 2

숫자 카드 N개를 가지고 있다.

M개의 카드를 주었을 때 몇 개가 있는지 구하라.

제약사항

  • 0 < N, M <= 500,000
  • -10,000,000 <= Input <= 10,000,000

주의 사항

없다.

CPP풀이

숫자 카드2_10816.cpp

/**
 * 백준 숫자 카드2_10816
 * 숫자 카드 N개를 가지고 있다.
 * M개의 카드를 주었을 때 몇 개가 있는지 구하라.
 * 
 * 제한사항
 *****************************************
 * 0 < N, M <= 500,000                   *
 * -10,000,000 <= Input <= 10,000,000    *
 *****************************************
 *
 *
 *
 * 주의
 * 없다.
 * 
 * 풀이시간 20분
 */


#include <iostream>
#include <string>
using namespace std;

int indexerCount[20000001] = { 0 };

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

    cin >> N;

    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        indexerCount[tmp + 10000000]++;
    }

    cin >> M;
    for (int i = 0; i < M; i++)
    {
        int tmp;
        cin >> tmp;
        cout << indexerCount[tmp + 10000000] << ' '; 
    }

    cout << '\n';
    return 0;
}

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

 

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

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

github.com